Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1 | #include "fio.h" |
| 2 | #include "profile.h" |
| 3 | #include "debug.h" |
| 4 | #include "flist.h" |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 5 | #include "options.h" |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 6 | |
| 7 | static FLIST_HEAD(profile_list); |
| 8 | |
Jens Axboe | 15dc193 | 2010-03-05 10:59:06 +0100 | [diff] [blame] | 9 | struct profile_ops *find_profile(const char *profile) |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 10 | { |
Jens Axboe | 15dc193 | 2010-03-05 10:59:06 +0100 | [diff] [blame] | 11 | struct profile_ops *ops = NULL; |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 12 | struct flist_head *n; |
| 13 | |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 14 | flist_for_each(n, &profile_list) { |
| 15 | ops = flist_entry(n, struct profile_ops, list); |
| 16 | if (!strcmp(profile, ops->name)) |
| 17 | break; |
| 18 | |
| 19 | ops = NULL; |
| 20 | } |
| 21 | |
Jens Axboe | 15dc193 | 2010-03-05 10:59:06 +0100 | [diff] [blame] | 22 | return ops; |
| 23 | } |
| 24 | |
| 25 | int load_profile(const char *profile) |
| 26 | { |
| 27 | struct profile_ops *ops; |
| 28 | |
| 29 | dprint(FD_PROFILE, "loading profile '%s'\n", profile); |
| 30 | |
| 31 | ops = find_profile(profile); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 32 | if (ops) { |
Jens Axboe | d4afedf | 2013-05-22 22:21:29 +0200 | [diff] [blame] | 33 | if (ops->prep_cmd()) { |
Jens Axboe | 9077755 | 2013-05-24 09:09:39 +0200 | [diff] [blame] | 34 | log_err("fio: profile %s prep failed\n", profile); |
Jens Axboe | d4afedf | 2013-05-22 22:21:29 +0200 | [diff] [blame] | 35 | return 1; |
| 36 | } |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 37 | add_job_opts(ops->cmdline, FIO_CLIENT_TYPE_CLI); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | log_err("fio: profile '%s' not found\n", profile); |
| 42 | return 1; |
| 43 | } |
| 44 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 45 | static int add_profile_options(struct profile_ops *ops) |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 46 | { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 47 | struct fio_option *o; |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 48 | |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 49 | if (!ops->options) |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 50 | return 0; |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 51 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 52 | o = ops->options; |
| 53 | while (o->name) { |
| 54 | o->prof_name = ops->name; |
Jens Axboe | 7b504ed | 2014-02-11 14:19:38 -0700 | [diff] [blame] | 55 | o->prof_opts = ops->opt_data; |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 56 | if (add_option(o)) |
| 57 | return 1; |
| 58 | o++; |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 59 | } |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 60 | |
| 61 | return 0; |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 64 | int register_profile(struct profile_ops *ops) |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 65 | { |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 66 | int ret; |
| 67 | |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 68 | dprint(FD_PROFILE, "register profile '%s'\n", ops->name); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 69 | |
Jens Axboe | f5b6bb8 | 2010-03-05 10:09:59 +0100 | [diff] [blame] | 70 | ret = add_profile_options(ops); |
| 71 | if (!ret) { |
| 72 | flist_add_tail(&ops->list, &profile_list); |
| 73 | add_opt_posval("profile", ops->name, ops->desc); |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | invalidate_profile_options(ops->name); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 78 | return ret; |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void unregister_profile(struct profile_ops *ops) |
| 82 | { |
| 83 | dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name); |
| 84 | flist_del(&ops->list); |
Jens Axboe | 07b3232 | 2010-03-05 09:48:44 +0100 | [diff] [blame] | 85 | invalidate_profile_options(ops->name); |
Jens Axboe | f5b6bb8 | 2010-03-05 10:09:59 +0100 | [diff] [blame] | 86 | del_opt_posval("profile", ops->name); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 87 | } |
Jens Axboe | 15dc193 | 2010-03-05 10:59:06 +0100 | [diff] [blame] | 88 | |
| 89 | void profile_add_hooks(struct thread_data *td) |
| 90 | { |
| 91 | struct profile_ops *ops; |
| 92 | |
| 93 | if (!exec_profile) |
| 94 | return; |
| 95 | |
| 96 | ops = find_profile(exec_profile); |
| 97 | if (!ops) |
| 98 | return; |
| 99 | |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 100 | if (ops->io_ops) { |
Jens Axboe | 7eb3657 | 2010-03-08 13:58:49 +0100 | [diff] [blame] | 101 | td->prof_io_ops = *ops->io_ops; |
Jens Axboe | d72be54 | 2012-11-30 19:37:46 +0100 | [diff] [blame] | 102 | td->flags |= TD_F_PROFILE_OPS; |
| 103 | } |
Jens Axboe | 15dc193 | 2010-03-05 10:59:06 +0100 | [diff] [blame] | 104 | } |
Jens Axboe | 58c55ba | 2010-03-09 12:20:08 +0100 | [diff] [blame] | 105 | |
| 106 | int profile_td_init(struct thread_data *td) |
| 107 | { |
| 108 | struct prof_io_ops *ops = &td->prof_io_ops; |
| 109 | |
| 110 | if (ops->td_init) |
| 111 | return ops->td_init(td); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | void profile_td_exit(struct thread_data *td) |
| 117 | { |
| 118 | struct prof_io_ops *ops = &td->prof_io_ops; |
| 119 | |
| 120 | if (ops->td_exit) |
| 121 | ops->td_exit(td); |
| 122 | } |