File: workqueue.h

package info (click to toggle)
fio 3.12-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 4,488 kB
  • sloc: ansic: 65,165; sh: 3,284; python: 1,978; makefile: 657; yacc: 204; lex: 184
file content (119 lines) | stat: -rw-r--r-- 2,812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef FIO_RATE_H
#define FIO_RATE_H

#include <inttypes.h>
#include <pthread.h>

#include "flist.h"
#include "lib/types.h"

struct sk_out;
struct thread_data;

struct workqueue_work {
	struct flist_head list;
};

struct submit_worker {
	pthread_t thread;
	pthread_mutex_t lock;
	pthread_cond_t cond;
	struct flist_head work_list;
	unsigned int flags;
	unsigned int index;
	uint64_t seq;
	struct workqueue *wq;
	void *priv;
	struct sk_out *sk_out;
};

typedef int (workqueue_work_fn)(struct submit_worker *, struct workqueue_work *);
typedef bool (workqueue_pre_sleep_flush_fn)(struct submit_worker *);
typedef void (workqueue_pre_sleep_fn)(struct submit_worker *);
typedef int (workqueue_alloc_worker_fn)(struct submit_worker *);
typedef void (workqueue_free_worker_fn)(struct submit_worker *);
typedef int (workqueue_init_worker_fn)(struct submit_worker *);
typedef void (workqueue_exit_worker_fn)(struct submit_worker *, unsigned int *);
typedef void (workqueue_update_acct_fn)(struct submit_worker *);

struct workqueue_ops {
	workqueue_work_fn *fn;
	workqueue_pre_sleep_flush_fn *pre_sleep_flush_fn;
	workqueue_pre_sleep_fn *pre_sleep_fn;

	workqueue_update_acct_fn *update_acct_fn;

	workqueue_alloc_worker_fn *alloc_worker_fn;
	workqueue_free_worker_fn *free_worker_fn;

	workqueue_init_worker_fn *init_worker_fn;
	workqueue_exit_worker_fn *exit_worker_fn;

	unsigned int nice;
};

struct workqueue {
	unsigned int max_workers;

	struct thread_data *td;
	struct workqueue_ops ops;

	uint64_t work_seq;
	struct submit_worker *workers;
	unsigned int next_free_worker;

	pthread_cond_t flush_cond;
	pthread_mutex_t flush_lock;
	pthread_mutex_t stat_lock;
	volatile int wake_idle;
};

int workqueue_init(struct thread_data *td, struct workqueue *wq, struct workqueue_ops *ops, unsigned int max_workers, struct sk_out *sk_out);
void workqueue_exit(struct workqueue *wq);

void workqueue_enqueue(struct workqueue *wq, struct workqueue_work *work);
void workqueue_flush(struct workqueue *wq);

static inline bool workqueue_pre_sleep_check(struct submit_worker *sw)
{
	struct workqueue *wq = sw->wq;

	if (!wq->ops.pre_sleep_flush_fn)
		return false;

	return wq->ops.pre_sleep_flush_fn(sw);
}

static inline void workqueue_pre_sleep(struct submit_worker *sw)
{
	struct workqueue *wq = sw->wq;

	if (wq->ops.pre_sleep_fn)
		wq->ops.pre_sleep_fn(sw);
}

static inline int workqueue_init_worker(struct submit_worker *sw)
{
	struct workqueue *wq = sw->wq;

	if (!wq->ops.init_worker_fn)
		return 0;

	return wq->ops.init_worker_fn(sw);
}

static inline void workqueue_exit_worker(struct submit_worker *sw,
					 unsigned int *sum_cnt)
{
	struct workqueue *wq = sw->wq;
	unsigned int tmp = 1;

	if (!wq->ops.exit_worker_fn)
		return;

	if (!sum_cnt)
		sum_cnt = &tmp;

	wq->ops.exit_worker_fn(sw, sum_cnt);
}
#endif