|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/workQueueHandle.h#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#ifndef WORK_QUEUE_HANDLE_H
|
|
Packit Service |
310c69 |
#define WORK_QUEUE_HANDLE_H
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include <linux/version.h>
|
|
Packit Service |
310c69 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)
|
|
Packit Service |
310c69 |
#include <linux/sched/task_stack.h>
|
|
Packit Service |
310c69 |
#else
|
|
Packit Service |
310c69 |
#include <linux/sched.h>
|
|
Packit Service |
310c69 |
#endif
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "workQueueInternals.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Layout of a special structure stored at a consistent place on the
|
|
Packit Service |
310c69 |
* stack in work queue threads.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
typedef struct workQueueStackHandle {
|
|
Packit Service |
310c69 |
unsigned long nonce;
|
|
Packit Service |
310c69 |
SimpleWorkQueue *queue;
|
|
Packit Service |
310c69 |
} WorkQueueStackHandle;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
typedef struct workQueueStackHandleGlobals {
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Location in the stack, relative to the task structure which is
|
|
Packit Service |
310c69 |
* contained in the same memory allocation.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
long offset;
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* A lock is used to guard against multiple updaters, but once an
|
|
Packit Service |
310c69 |
* update is done, the offset variable will be read-only.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
spinlock_t offsetLock;
|
|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* A nonce chosen differently each time the module is loaded, used
|
|
Packit Service |
310c69 |
* as a marker so we can check that the current thread really is a
|
|
Packit Service |
310c69 |
* work queue thread. Set at module initialization time, before any
|
|
Packit Service |
310c69 |
* work queues are created.
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
unsigned long nonce;
|
|
Packit Service |
310c69 |
} WorkQueueStackHandleGlobals;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
extern WorkQueueStackHandleGlobals workQueueStackHandleGlobals;
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Initialize a stack handle associated with a work queue.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @param [out] handle The handle to be initialized
|
|
Packit Service |
310c69 |
* @param [in] queue The work queue pointer
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void initializeWorkQueueStackHandle(WorkQueueStackHandle *handle,
|
|
Packit Service |
310c69 |
SimpleWorkQueue *queue);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Return the work queue pointer recorded at initialization time in
|
|
Packit Service |
310c69 |
* the work-queue stack handle initialized on the stack of the current
|
|
Packit Service |
310c69 |
* thread, if any.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* @return the work queue pointer, or NULL
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
static inline SimpleWorkQueue *getCurrentThreadWorkQueue(void)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
WorkQueueStackHandle *handle
|
|
Packit Service |
310c69 |
= (WorkQueueStackHandle *)(task_stack_page(current)
|
|
Packit Service |
310c69 |
+ workQueueStackHandleGlobals.offset);
|
|
Packit Service |
310c69 |
if (likely(handle->nonce == workQueueStackHandleGlobals.nonce)) {
|
|
Packit Service |
310c69 |
return handle->queue;
|
|
Packit Service |
310c69 |
} else {
|
|
Packit Service |
310c69 |
return NULL;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**
|
|
Packit Service |
310c69 |
* Initialize the global state used by the work-queue stack-handle
|
|
Packit Service |
310c69 |
* code.
|
|
Packit Service |
310c69 |
**/
|
|
Packit Service |
310c69 |
void initWorkQueueStackHandleOnce(void);
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#endif // WORK_QUEUE_HANDLE_H
|