Merge pull request #3 from lxbsz/wip-52438
[ffsb.git] / ffsb_op.h
1 /*
2  *   Copyright (c) International Business Machines Corp., 2001-2004
3  *
4  *   This program is free software;  you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License as published by
6  *   the Free Software Foundation; either version 2 of the License, or
7  *   (at your option) any later version.
8  *
9  *   This program is distributed in the hope that it will be useful,
10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
12  *   the GNU General Public License for more details.
13  *
14  *   You should have received a copy of the GNU General Public License
15  *   along with this program;  if not, write to the Free Software
16  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 #ifndef _FFSB_OP_H_
19 #define _FFSB_OP_H_
20
21 #include <stdlib.h>
22 #include <sys/types.h>
23 #include <inttypes.h>
24
25 struct ffsb_op_results;
26 struct ffsb_thread;
27 struct ffsb_fs;
28
29 #define NA 0x00
30 #define READ 0x01
31 #define WRITE 0x02
32
33 /* This file handles all of the operations FFSB supports.  It has
34  * tight interactions with the filesystem objects, but is otherwise
35  * pretty abstract.
36  */
37
38 /* The op callback */
39 typedef void (*ffsb_op_fn)(struct ffsb_thread *, struct ffsb_fs *,
40                              unsigned op_num);
41
42 /* Operation results printing function */
43 typedef void (*ffsb_op_print_fn)(struct ffsb_op_results *, double secs,
44                                   unsigned int op_num);
45
46 /* Operation specific initialization for a filesystem */
47 typedef void (*ffsb_op_fs_fn)(struct ffsb_fs *, unsigned opnum);
48
49 typedef struct ffsb_op {
50         unsigned int op_id;
51         char *op_name;
52         ffsb_op_fn op_fn;
53
54         unsigned int throughput;
55         /* The point of these two fields is to determine which set of
56          * files are being worked on.  Currently either data, meta, or
57          * aging.  Data and meta are mutually exclusive, so we only
58          * need two funcs.
59          */
60         ffsb_op_fs_fn op_bench;
61         ffsb_op_fs_fn op_age;
62 } ffsb_op_t;
63
64 /* List of all operations, located in ffsb_op.c */
65 extern ffsb_op_t ffsb_op_list[];
66
67 /* This *must* be updated when a new operation is added or one is
68  * removed several other structures use it for statically sized arrays
69  */
70 #define FFSB_NUMOPS (15)
71
72 /* Returns index of an op.
73  * Returns -1 if opname isn't found, and its case sensitive :)
74  */
75 int ops_find_op(char *opname);
76
77 typedef struct ffsb_op_results {
78         /* Count of how many times each op was run */
79         unsigned int ops[FFSB_NUMOPS];
80         unsigned int op_weight[FFSB_NUMOPS];
81         uint64_t bytes[FFSB_NUMOPS];
82
83         uint64_t read_bytes;
84         uint64_t write_bytes;
85 } ffsb_op_results_t;
86
87 void init_ffsb_op_results(struct ffsb_op_results *);
88 void print_results(struct ffsb_op_results *results, double runtime);
89 char *op_get_name(int opnum);
90
91 /* Setup the ops for the benchmark */
92 void ops_setup_bench(struct ffsb_fs *fs);
93
94 /* setup the ops for aging the filesystem */
95 void ops_setup_age(struct ffsb_fs *fs);
96
97 void add_results(struct ffsb_op_results *target, struct ffsb_op_results *src);
98
99 /* Run this op, using this thread state, on this filesystem */
100 void do_op(struct ffsb_thread *ft, struct ffsb_fs *fs, unsigned op_num);
101
102 #endif /* _FFSB_OP_H_ */