|
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/batchProcessor.h#2 $
|
|
Packit Service |
b3514a |
*/
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#ifndef BATCHPROCESSOR_H
|
|
Packit Service |
b3514a |
#define BATCHPROCESSOR_H
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#include "kernelTypes.h"
|
|
Packit Service |
b3514a |
#include "util/funnelQueue.h"
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Control data for managing collections of objects to be operated on
|
|
Packit Service |
b3514a |
* by a specified function. May be used when the work function is
|
|
Packit Service |
b3514a |
* lightweight enough or cache-contentious enough that it makes sense
|
|
Packit Service |
b3514a |
* to try to accumulate multiple objects and operate on them all at
|
|
Packit Service |
b3514a |
* once in one thread.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* The work function is run in one of the kernel layer's "CPU queues",
|
|
Packit Service |
b3514a |
* and care is taken to ensure that only one invocation can be running
|
|
Packit Service |
b3514a |
* or scheduled at any given time. It can loop calling nextBatchItem
|
|
Packit Service |
b3514a |
* repeatedly until there are no more objects to operate on. It should
|
|
Packit Service |
b3514a |
* also call condReschedBatchProcessor now and then, to play nicely
|
|
Packit Service |
b3514a |
* with the OS scheduler.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* Objects to operate on are manipulated through a FunnelQueueEntry
|
|
Packit Service |
b3514a |
* object which must be contained within them.
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
typedef struct batchProcessor BatchProcessor;
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
typedef void (*BatchProcessorCallback)(BatchProcessor *batch, void *closure);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Creates a batch-processor control structure.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] layer The kernel layer data, used to enqueue work items
|
|
Packit Service |
b3514a |
* @param [in] callback A function to process the accumulated objects
|
|
Packit Service |
b3514a |
* @param [in] closure A private data pointer for use by the callback
|
|
Packit Service |
b3514a |
* @param [out] batchPtr Where to store the pointer to the new object
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return UDS_SUCCESS or an error code
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
int makeBatchProcessor(KernelLayer *layer,
|
|
Packit Service |
b3514a |
BatchProcessorCallback callback,
|
|
Packit Service |
b3514a |
void *closure,
|
|
Packit Service |
b3514a |
BatchProcessor **batchPtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Adds an object to the processing queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* If the callback function is not currently running or scheduled to be run,
|
|
Packit Service |
b3514a |
* it gets queued up to run.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] batch The batch-processor data
|
|
Packit Service |
b3514a |
* @param [in] item The handle on the new object to add
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void addToBatchProcessor(BatchProcessor *batch, KvdoWorkItem *item);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Fetches the next object in the processing queue.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] batch The batch-processor data
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @return An object pointer or NULL
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
KvdoWorkItem *nextBatchItem(BatchProcessor *batch)
|
|
Packit Service |
b3514a |
__attribute__((warn_unused_result));
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Free the batch-processor data and null out the pointer.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in,out] batchPtr Where the BatchProcessor pointer is stored
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void freeBatchProcessor(BatchProcessor **batchPtr);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
/**
|
|
Packit Service |
b3514a |
* Yield control to the scheduler if the kernel has indicated that
|
|
Packit Service |
b3514a |
* other work needs to run on the current processor.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* The data structure is needed so that the spin lock can be
|
|
Packit Service |
b3514a |
* (conditionally) released and re-acquired.
|
|
Packit Service |
b3514a |
*
|
|
Packit Service |
b3514a |
* @param [in] batch The batch-processor data
|
|
Packit Service |
b3514a |
**/
|
|
Packit Service |
b3514a |
void condReschedBatchProcessor(BatchProcessor *batch);
|
|
Packit Service |
b3514a |
|
|
Packit Service |
b3514a |
#endif // BATCHPROCESSOR_H
|