2015-12-12 00:15:50 +00:00
|
|
|
/*
|
2010-05-17 22:18:00 +00:00
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
2013-03-05 01:26:55 +00:00
|
|
|
* For details, see <http://zfsonlinux.org/>.
|
2010-05-17 22:18:00 +00:00
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
2015-12-12 00:15:50 +00:00
|
|
|
*/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2008-02-28 00:52:31 +00:00
|
|
|
#ifndef _SPL_TASKQ_H
|
2015-12-12 00:15:50 +00:00
|
|
|
#define _SPL_TASKQ_H
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2008-02-27 19:09:51 +00:00
|
|
|
#include <linux/module.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
2008-04-25 22:10:47 +00:00
|
|
|
#include <linux/kthread.h>
|
2017-07-24 02:32:14 +00:00
|
|
|
#include <linux/wait_compat.h>
|
2008-03-01 00:45:59 +00:00
|
|
|
#include <sys/types.h>
|
2008-12-24 00:27:36 +00:00
|
|
|
#include <sys/thread.h>
|
2015-10-19 12:47:52 +00:00
|
|
|
#include <sys/rwlock.h>
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2015-12-12 00:15:50 +00:00
|
|
|
#define TASKQ_NAMELEN 31
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2015-12-12 00:15:50 +00:00
|
|
|
#define TASKQ_PREPOPULATE 0x00000001
|
|
|
|
#define TASKQ_CPR_SAFE 0x00000002
|
|
|
|
#define TASKQ_DYNAMIC 0x00000004
|
|
|
|
#define TASKQ_THREADS_CPU_PCT 0x00000008
|
|
|
|
#define TASKQ_DC_BATCH 0x00000010
|
|
|
|
#define TASKQ_ACTIVE 0x80000000
|
2008-02-26 20:36:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
|
2008-04-25 22:10:47 +00:00
|
|
|
* KM_SLEEP/KM_NOSLEEP. TQ_NOQUEUE/TQ_NOALLOC are set particularly
|
|
|
|
* large so as not to conflict with already used GFP_* defines.
|
2008-02-26 20:36:04 +00:00
|
|
|
*/
|
2015-12-12 00:15:50 +00:00
|
|
|
#define TQ_SLEEP 0x00000000
|
|
|
|
#define TQ_NOSLEEP 0x00000001
|
|
|
|
#define TQ_PUSHPAGE 0x00000002
|
|
|
|
#define TQ_NOQUEUE 0x01000000
|
|
|
|
#define TQ_NOALLOC 0x02000000
|
|
|
|
#define TQ_NEW 0x04000000
|
|
|
|
#define TQ_FRONT 0x08000000
|
|
|
|
|
2016-10-28 21:23:30 +00:00
|
|
|
/*
|
|
|
|
* Reserved taskqid values.
|
|
|
|
*/
|
|
|
|
#define TASKQID_INVALID ((taskqid_t)0)
|
|
|
|
#define TASKQID_INITIAL ((taskqid_t)1)
|
|
|
|
|
2015-12-12 00:15:50 +00:00
|
|
|
/*
|
|
|
|
* spin_lock(lock) and spin_lock_nested(lock,0) are equivalent,
|
2015-10-13 23:56:51 +00:00
|
|
|
* so TQ_LOCK_DYNAMIC must not evaluate to 0
|
|
|
|
*/
|
|
|
|
typedef enum tq_lock_role {
|
|
|
|
TQ_LOCK_GENERAL = 0,
|
|
|
|
TQ_LOCK_DYNAMIC = 1,
|
|
|
|
} tq_lock_role_t;
|
|
|
|
|
2012-12-06 20:38:19 +00:00
|
|
|
typedef unsigned long taskqid_t;
|
|
|
|
typedef void (task_func_t)(void *);
|
|
|
|
|
2008-04-25 22:10:47 +00:00
|
|
|
typedef struct taskq {
|
2015-12-12 00:15:50 +00:00
|
|
|
spinlock_t tq_lock; /* protects taskq_t */
|
|
|
|
char *tq_name; /* taskq name */
|
2015-10-19 12:47:52 +00:00
|
|
|
int tq_instance; /* instance of tq_name */
|
2015-12-12 00:15:50 +00:00
|
|
|
struct list_head tq_thread_list; /* list of all threads */
|
|
|
|
struct list_head tq_active_list; /* list of active threads */
|
|
|
|
int tq_nactive; /* # of active threads */
|
|
|
|
int tq_nthreads; /* # of existing threads */
|
|
|
|
int tq_nspawn; /* # of threads being spawned */
|
|
|
|
int tq_maxthreads; /* # of threads maximum */
|
|
|
|
int tq_pri; /* priority */
|
2015-10-19 12:47:52 +00:00
|
|
|
int tq_minalloc; /* min taskq_ent_t pool size */
|
|
|
|
int tq_maxalloc; /* max taskq_ent_t pool size */
|
|
|
|
int tq_nalloc; /* cur taskq_ent_t pool size */
|
2015-12-12 00:15:50 +00:00
|
|
|
uint_t tq_flags; /* flags */
|
|
|
|
taskqid_t tq_next_id; /* next pend/work id */
|
|
|
|
taskqid_t tq_lowest_id; /* lowest pend/work id */
|
2015-10-19 12:47:52 +00:00
|
|
|
struct list_head tq_free_list; /* free taskq_ent_t's */
|
|
|
|
struct list_head tq_pend_list; /* pending taskq_ent_t's */
|
|
|
|
struct list_head tq_prio_list; /* priority pending taskq_ent_t's */
|
|
|
|
struct list_head tq_delay_list; /* delayed taskq_ent_t's */
|
|
|
|
struct list_head tq_taskqs; /* all taskq_t's */
|
2017-07-24 02:32:14 +00:00
|
|
|
spl_wait_queue_head_t tq_work_waitq; /* new work waitq */
|
|
|
|
spl_wait_queue_head_t tq_wait_waitq; /* wait waitq */
|
2015-12-12 00:15:50 +00:00
|
|
|
tq_lock_role_t tq_lock_class; /* class when taking tq_lock */
|
2008-04-25 22:10:47 +00:00
|
|
|
} taskq_t;
|
2008-02-26 20:36:04 +00:00
|
|
|
|
2012-12-06 20:38:19 +00:00
|
|
|
typedef struct taskq_ent {
|
|
|
|
spinlock_t tqent_lock;
|
2017-07-24 02:32:14 +00:00
|
|
|
spl_wait_queue_head_t tqent_waitq;
|
2012-12-06 20:38:19 +00:00
|
|
|
struct timer_list tqent_timer;
|
|
|
|
struct list_head tqent_list;
|
|
|
|
taskqid_t tqent_id;
|
|
|
|
task_func_t *tqent_func;
|
|
|
|
void *tqent_arg;
|
|
|
|
taskq_t *tqent_taskq;
|
|
|
|
uintptr_t tqent_flags;
|
2016-01-28 00:55:14 +00:00
|
|
|
unsigned long tqent_birth;
|
2012-12-06 20:38:19 +00:00
|
|
|
} taskq_ent_t;
|
|
|
|
|
2015-12-12 00:15:50 +00:00
|
|
|
#define TQENT_FLAG_PREALLOC 0x1
|
|
|
|
#define TQENT_FLAG_CANCEL 0x2
|
2012-12-06 20:38:19 +00:00
|
|
|
|
2011-12-06 01:32:48 +00:00
|
|
|
typedef struct taskq_thread {
|
2012-12-06 20:57:42 +00:00
|
|
|
struct list_head tqt_thread_list;
|
|
|
|
struct list_head tqt_active_list;
|
|
|
|
struct task_struct *tqt_thread;
|
|
|
|
taskq_t *tqt_tq;
|
|
|
|
taskqid_t tqt_id;
|
2012-12-06 20:38:19 +00:00
|
|
|
taskq_ent_t *tqt_task;
|
2012-12-06 20:57:42 +00:00
|
|
|
uintptr_t tqt_flags;
|
2011-12-06 01:32:48 +00:00
|
|
|
} taskq_thread_t;
|
|
|
|
|
2009-01-05 23:08:03 +00:00
|
|
|
/* Global system-wide dynamic task queue available for all consumers */
|
|
|
|
extern taskq_t *system_taskq;
|
2016-12-08 21:00:20 +00:00
|
|
|
/* Global dynamic task queue for long delay */
|
|
|
|
extern taskq_t *system_delay_taskq;
|
2009-01-05 23:08:03 +00:00
|
|
|
|
2015-10-19 12:47:52 +00:00
|
|
|
/* List of all taskqs */
|
|
|
|
extern struct list_head tq_list;
|
|
|
|
extern struct rw_semaphore tq_list_sem;
|
|
|
|
|
2012-12-06 21:04:27 +00:00
|
|
|
extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
|
2012-12-06 20:38:19 +00:00
|
|
|
extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *,
|
|
|
|
uint_t, clock_t);
|
2012-12-06 21:04:27 +00:00
|
|
|
extern void taskq_dispatch_ent(taskq_t *, task_func_t, void *, uint_t,
|
|
|
|
taskq_ent_t *);
|
|
|
|
extern int taskq_empty_ent(taskq_ent_t *);
|
|
|
|
extern void taskq_init_ent(taskq_ent_t *);
|
|
|
|
extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
|
|
|
|
extern void taskq_destroy(taskq_t *);
|
|
|
|
extern void taskq_wait_id(taskq_t *, taskqid_t);
|
2015-05-14 19:26:51 +00:00
|
|
|
extern void taskq_wait_outstanding(taskq_t *, taskqid_t);
|
2012-12-06 21:04:27 +00:00
|
|
|
extern void taskq_wait(taskq_t *);
|
2012-12-06 20:38:19 +00:00
|
|
|
extern int taskq_cancel_id(taskq_t *, taskqid_t);
|
2015-12-02 22:52:46 +00:00
|
|
|
extern int taskq_member(taskq_t *, kthread_t *);
|
2012-12-06 21:04:27 +00:00
|
|
|
|
2015-12-12 00:15:50 +00:00
|
|
|
#define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \
|
2012-12-06 21:04:27 +00:00
|
|
|
taskq_create(name, nthreads, pri, min, max, flags)
|
2015-12-12 00:15:50 +00:00
|
|
|
#define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \
|
2015-07-24 17:32:55 +00:00
|
|
|
taskq_create(name, nthreads, maxclsyspri, min, max, flags)
|
2008-04-25 22:10:47 +00:00
|
|
|
|
2009-01-05 23:08:03 +00:00
|
|
|
int spl_taskq_init(void);
|
|
|
|
void spl_taskq_fini(void);
|
|
|
|
|
2008-02-28 00:52:31 +00:00
|
|
|
#endif /* _SPL_TASKQ_H */
|