Blame source/vdo/kernel/workQueueHandle.h

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