|
Packit Service |
b3514a |
/*
|
|
Packit Service |
b3514a |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
b3514a |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
b3514a |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
b3514a |
* of the License, or (at your option) any later version.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
b3514a |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b3514a |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
b3514a |
* GNU General Public License for more details.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
b3514a |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
b3514a |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
b3514a |
* 02110-1301, USA.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/workQueue.h#2 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#ifndef ALBIREO_WORK_QUEUE_H
|
|
Packit Service |
b3514a |
#define ALBIREO_WORK_QUEUE_H
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include <linux/kobject.h>
|
|
Packit Service |
b3514a |
#include <linux/sched.h> /* for TASK_COMM_LEN */
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "kernelTypes.h"
|
|
Packit Service |
b3514a |
#include "util/funnelQueue.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
enum {
|
|
Packit Service |
b3514a |
MAX_QUEUE_NAME_LEN = TASK_COMM_LEN,
|
|
Packit Service |
b3514a |
/** Maximum number of action definitions per work queue type */
|
|
Packit Service |
b3514a |
WORK_QUEUE_ACTION_COUNT = 8,
|
|
Packit Service |
b3514a |
/** Number of priority values available */
|
|
Packit Service |
b3514a |
WORK_QUEUE_PRIORITY_COUNT = 4,
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
struct kvdoWorkItem {
|
|
Packit Service |
b3514a |
/** Entry link for lock-free work queue */
|
|
Packit Service |
b3514a |
FunnelQueueEntry workQueueEntryLink;
|
|
Packit Service |
b3514a |
/** Function to be called */
|
|
Packit Service |
b3514a |
KvdoWorkFunction work;
|
|
Packit Service |
b3514a |
/** Optional alternate function for display in queue stats */
|
|
Packit Service |
b3514a |
void *statsFunction;
|
|
Packit Service |
b3514a |
/** An index into the statistics table; filled in by workQueueStats code */
|
|
Packit Service |
b3514a |
unsigned int statTableIndex;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* The action code given to setupWorkItem, from which a priority will be
|
|
Packit Service |
b3514a |
* determined.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
unsigned int action;
|
|
Packit Service |
b3514a |
/** The work queue in which the item is enqueued, or NULL if not enqueued. */
|
|
Packit Service |
b3514a |
KvdoWorkQueue *myQueue;
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Time at which to execute in jiffies for a delayed work item, or zero to
|
|
Packit Service |
b3514a |
* queue for execution ASAP.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
Jiffies executionTime;
|
|
Packit Service |
b3514a |
/** List management for delayed or expired work items */
|
|
Packit Service |
b3514a |
KvdoWorkItem *next;
|
|
Packit Service |
b3514a |
/** Time of enqueueing, in ns, for recording queue (waiting) time stats */
|
|
Packit Service |
b3514a |
uint64_t enqueueTime;
|
|
Packit Service |
b3514a |
};
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Table entries defining an action.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Actions are intended to distinguish general classes of activity for
|
|
Packit Service |
b3514a |
* prioritization purposes, but not necessarily to indicate specific work
|
|
Packit Service |
b3514a |
* functions. They are indicated to setupWorkItem numerically, using an
|
|
Packit Service |
b3514a |
* enumerator defined per kind of work queue -- bio submission work queue
|
|
Packit Service |
b3514a |
* actions use BioQAction, cpu actions use CPUQAction, etc. For example, for
|
|
Packit Service |
b3514a |
* the CPU work queues, data compression can be prioritized separately from
|
|
Packit Service |
b3514a |
* final cleanup processing of a KVIO or from dedupe verification; base code
|
|
Packit Service |
b3514a |
* threads prioritize all VIO callback invocation the same, but separate from
|
|
Packit Service |
b3514a |
* sync or heartbeat operations. The bio acknowledgement work queue, on the
|
|
Packit Service |
b3514a |
* other hand, only does one thing, so it only defines one action code.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Action codes values must be small integers, 0 through
|
|
Packit Service |
b3514a |
* WORK_QUEUE_ACTION_COUNT-1, and should not be duplicated for a queue type.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* A table of KvdoWorkQueueAction entries embedded in KvdoWorkQueueType
|
|
Packit Service |
b3514a |
* specifies the name, code, and priority for each type of action in the work
|
|
Packit Service |
b3514a |
* queue. The table can have at most WORK_QUEUE_ACTION_COUNT entries, but a
|
|
Packit Service |
b3514a |
* NULL name indicates an earlier end to the table.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Priorities may be specified as values from 0 through
|
|
Packit Service |
b3514a |
* WORK_QUEUE_PRIORITY_COUNT-1, higher values indicating higher priority.
|
|
Packit Service |
b3514a |
* Priorities are just strong suggestions; it's possible for a lower-priority
|
|
Packit Service |
b3514a |
* work item scheduled right after a high-priority one to be run first, if the
|
|
Packit Service |
b3514a |
* worker thread happens to be scanning its queues at just the wrong moment,
|
|
Packit Service |
b3514a |
* but the high-priority item will be picked up next.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Internally, the priorities in this table are used to initialize another
|
|
Packit Service |
b3514a |
* table in the constructed work queue object, and in internal builds,
|
|
Packit Service |
b3514a |
* device-mapper messages can be sent to change the priority for an action,
|
|
Packit Service |
b3514a |
* identified by name, in a running VDO device. Doing so does not affect the
|
|
Packit Service |
b3514a |
* priorities for other devices, or for future VDO device creation.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
typedef struct kvdoWorkQueueAction {
|
|
Packit Service |
b3514a |
/** Name of the action */
|
|
Packit Service |
b3514a |
char *name;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** The action code (per-type enum) */
|
|
Packit Service |
b3514a |
unsigned int code;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** The initial priority for this action */
|
|
Packit Service |
b3514a |
unsigned int priority;
|
|
Packit Service |
b3514a |
} KvdoWorkQueueAction;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef void (*KvdoWorkQueueFunction)(void *);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Static attributes of a work queue that are fixed at compile time
|
|
Packit Service |
b3514a |
* for a given call site. (Attributes that may be computed at run time
|
|
Packit Service |
b3514a |
* are passed as separate arguments.)
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
typedef struct kvdoWorkQueueType {
|
|
Packit Service |
b3514a |
/** A function to call in the new thread before servicing requests */
|
|
Packit Service |
b3514a |
KvdoWorkQueueFunction start;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** A function to call in the new thread when shutting down */
|
|
Packit Service |
b3514a |
KvdoWorkQueueFunction finish;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** A function to call in the new thread after running out of work */
|
|
Packit Service |
b3514a |
KvdoWorkQueueFunction suspend;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/** Table of actions for this work queue */
|
|
Packit Service |
b3514a |
KvdoWorkQueueAction actionTable[WORK_QUEUE_ACTION_COUNT];
|
|
Packit Service |
b3514a |
} KvdoWorkQueueType;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Create a work queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* If multiple threads are requested, work items will be distributed to them in
|
|
Packit Service |
b3514a |
* round-robin fashion.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] threadNamePrefix The per-device prefix to use in thread names
|
|
Packit Service |
b3514a |
* @param [in] name The queue name
|
|
Packit Service |
b3514a |
* @param [in] parentKobject The parent sysfs node
|
|
Packit Service |
b3514a |
* @param [in] owner The kernel layer owning the work queue
|
|
Packit Service |
b3514a |
* @param [in] private Private data of the queue for use by work
|
|
Packit Service |
b3514a |
* items or other queue-specific functions
|
|
Packit Service |
b3514a |
* @param [in] type The work queue type defining the lifecycle
|
|
Packit Service |
b3514a |
* functions, queue actions, priorities, and
|
|
Packit Service |
b3514a |
* timeout behavior
|
|
Packit Service |
b3514a |
* @param [in] threadCount Number of service threads to set up
|
|
Packit Service |
b3514a |
* @param [out] queuePtr Where to store the queue handle
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return VDO_SUCCESS or an error code
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int makeWorkQueue(const char *threadNamePrefix,
|
|
Packit Service |
b3514a |
const char *name,
|
|
Packit Service |
b3514a |
struct kobject *parentKobject,
|
|
Packit Service |
b3514a |
KernelLayer *owner,
|
|
Packit Service |
b3514a |
void *private,
|
|
Packit Service |
b3514a |
const KvdoWorkQueueType *type,
|
|
Packit Service |
b3514a |
unsigned int threadCount,
|
|
Packit Service |
b3514a |
KvdoWorkQueue **queuePtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Set up the fields of a work queue item.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Before the first setup call (setupWorkItem or setupWorkItemWithTimeout), the
|
|
Packit Service |
b3514a |
* work item must have been initialized to all-zero. Resetting a
|
|
Packit Service |
b3514a |
* previously-used work item does not require another memset.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* The action code is typically defined in a work-queue-type-specific
|
|
Packit Service |
b3514a |
* enumeration; see the description of KvdoWorkQueueAction.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item The work item to initialize
|
|
Packit Service |
b3514a |
* @param work The function pointer to execute
|
|
Packit Service |
b3514a |
* @param statsFunction A function pointer to record for stats, or NULL
|
|
Packit Service |
b3514a |
* @param action Action code, for determination of priority
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void setupWorkItem(KvdoWorkItem *item,
|
|
Packit Service |
b3514a |
KvdoWorkFunction work,
|
|
Packit Service |
b3514a |
void *statsFunction,
|
|
Packit Service |
b3514a |
unsigned int action);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Add a work item to a work queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* If the work item has a timeout that has already passed, the timeout
|
|
Packit Service |
b3514a |
* handler function may be invoked at this time.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queue The queue handle
|
|
Packit Service |
b3514a |
* @param item The work item to be processed
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void enqueueWorkQueue(KvdoWorkQueue *queue, KvdoWorkItem *item);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Add a work item to a work queue, to be run at a later point in time.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Currently delayed work items are used only in a very limited fashion -- at
|
|
Packit Service |
b3514a |
* most one at a time for any of the work queue types that use them -- and some
|
|
Packit Service |
b3514a |
* shortcuts have been taken that assume that that's the case. Multiple delayed
|
|
Packit Service |
b3514a |
* work items should work, but they will execute in the order they were
|
|
Packit Service |
b3514a |
* enqueued.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queue The queue handle
|
|
Packit Service |
b3514a |
* @param item The work item to be processed
|
|
Packit Service |
b3514a |
* @param executionTime When to run the work item (jiffies)
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void enqueueWorkQueueDelayed(KvdoWorkQueue *queue,
|
|
Packit Service |
b3514a |
KvdoWorkItem *item,
|
|
Packit Service |
b3514a |
Jiffies executionTime);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Shut down a work queue's worker thread.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Alerts the worker thread that it should shut down, and then waits
|
|
Packit Service |
b3514a |
* for it to do so.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* There should not be any new enqueueing of work items done once this
|
|
Packit Service |
b3514a |
* function is called. Any pending delayed work items will be
|
|
Packit Service |
b3514a |
* processed, as scheduled, before the worker thread shuts down, but
|
|
Packit Service |
b3514a |
* they must not re-queue themselves to run again.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queue The work queue to shut down
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void finishWorkQueue(KvdoWorkQueue *queue);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Free a work queue and null out the reference to it.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queuePtr Where the queue handle is found
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void freeWorkQueue(KvdoWorkQueue **queuePtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Print work queue state and statistics to the kernel log.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queue The work queue to examine
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void dumpWorkQueue(KvdoWorkQueue *queue);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Write to the buffer some info about the work item, for logging.
|
|
Packit Service |
b3514a |
* Since the common use case is dumping info about a lot of work items
|
|
Packit Service |
b3514a |
* to syslog all at once, the format favors brevity over readability.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item The work item
|
|
Packit Service |
b3514a |
* @param buffer The message buffer to fill in
|
|
Packit Service |
b3514a |
* @param length The length of the message buffer
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void dumpWorkItemToBuffer(KvdoWorkItem *item, char *buffer, size_t length);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Initialize work queue internals at module load time.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void initWorkQueueOnce(void);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Checks whether two work items have the same action codes
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param item1 The first item
|
|
Packit Service |
b3514a |
* @param item2 The second item
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return TRUE if the actions are the same, FALSE otherwise
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
static inline bool areWorkItemActionsEqual(KvdoWorkItem *item1,
|
|
Packit Service |
b3514a |
KvdoWorkItem *item2)
|
|
Packit Service |
b3514a |
{
|
|
Packit Service |
b3514a |
return item1->action == item2->action;
|
|
Packit Service |
b3514a |
}
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Returns the private data for the current thread's work queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The private data pointer, or NULL if none or if the current
|
|
Packit Service |
b3514a |
* thread is not a work queue thread.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void *getWorkQueuePrivateData(void);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Updates the private data pointer for the current thread's work queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param newData The new private data pointer
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void setWorkQueuePrivateData(void *newData);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Returns the work queue pointer for the current thread, if any.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The work queue pointer or NULL
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
KvdoWorkQueue *getCurrentWorkQueue(void);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Returns the kernel layer that owns the work queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param queue The work queue
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return The owner pointer supplied at work queue creation
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
KernelLayer *getWorkQueueOwner(KvdoWorkQueue *queue);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#endif /* ALBIREO_WORK_QUEUE_H */
|