Blame source/vdo/kernel/batchProcessor.h

Packit Service d40955
/*
Packit Service d40955
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service d40955
 *
Packit Service d40955
 * This program is free software; you can redistribute it and/or
Packit Service d40955
 * modify it under the terms of the GNU General Public License
Packit Service d40955
 * as published by the Free Software Foundation; either version 2
Packit Service d40955
 * of the License, or (at your option) any later version.
Packit Service d40955
 * 
Packit Service d40955
 * This program is distributed in the hope that it will be useful,
Packit Service d40955
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service d40955
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service d40955
 * GNU General Public License for more details.
Packit Service d40955
 * 
Packit Service d40955
 * You should have received a copy of the GNU General Public License
Packit Service d40955
 * along with this program; if not, write to the Free Software
Packit Service d40955
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service d40955
 * 02110-1301, USA. 
Packit Service d40955
 *
Packit Service d40955
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/kernel/batchProcessor.h#2 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#ifndef BATCHPROCESSOR_H
Packit Service d40955
#define BATCHPROCESSOR_H
Packit Service d40955
Packit Service d40955
#include "kernelTypes.h"
Packit Service d40955
#include "util/funnelQueue.h"
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Control data for managing collections of objects to be operated on
Packit Service d40955
 * by a specified function. May be used when the work function is
Packit Service d40955
 * lightweight enough or cache-contentious enough that it makes sense
Packit Service d40955
 * to try to accumulate multiple objects and operate on them all at
Packit Service d40955
 * once in one thread.
Packit Service d40955
 *
Packit Service d40955
 * The work function is run in one of the kernel layer's "CPU queues",
Packit Service d40955
 * and care is taken to ensure that only one invocation can be running
Packit Service d40955
 * or scheduled at any given time. It can loop calling nextBatchItem
Packit Service d40955
 * repeatedly until there are no more objects to operate on. It should
Packit Service d40955
 * also call condReschedBatchProcessor now and then, to play nicely
Packit Service d40955
 * with the OS scheduler.
Packit Service d40955
 *
Packit Service d40955
 * Objects to operate on are manipulated through a FunnelQueueEntry
Packit Service d40955
 * object which must be contained within them.
Packit Service d40955
 **/
Packit Service d40955
typedef struct batchProcessor BatchProcessor;
Packit Service d40955
Packit Service d40955
typedef void (*BatchProcessorCallback)(BatchProcessor *batch, void *closure);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Creates a batch-processor control structure.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  layer     The kernel layer data, used to enqueue work items
Packit Service d40955
 * @param [in]  callback  A function to process the accumulated objects
Packit Service d40955
 * @param [in]  closure   A private data pointer for use by the callback
Packit Service d40955
 * @param [out] batchPtr  Where to store the pointer to the new object
Packit Service d40955
 *
Packit Service d40955
 * @return   UDS_SUCCESS or an error code
Packit Service d40955
 **/
Packit Service d40955
int makeBatchProcessor(KernelLayer             *layer,
Packit Service d40955
                       BatchProcessorCallback   callback,
Packit Service d40955
                       void                    *closure,
Packit Service d40955
                       BatchProcessor         **batchPtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Adds an object to the processing queue.
Packit Service d40955
 *
Packit Service d40955
 * 

If the callback function is not currently running or scheduled to be run,

Packit Service d40955
 * it gets queued up to run.
Packit Service d40955
 *
Packit Service d40955
 * @param [in] batch  The batch-processor data
Packit Service d40955
 * @param [in] item   The handle on the new object to add
Packit Service d40955
 **/
Packit Service d40955
void addToBatchProcessor(BatchProcessor *batch, KvdoWorkItem *item);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Fetches the next object in the processing queue.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  batch  The batch-processor data
Packit Service d40955
 *
Packit Service d40955
 * @return   An object pointer or NULL
Packit Service d40955
 **/
Packit Service d40955
KvdoWorkItem *nextBatchItem(BatchProcessor *batch)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Free the batch-processor data and null out the pointer.
Packit Service d40955
 *
Packit Service d40955
 * @param [in,out] batchPtr  Where the BatchProcessor pointer is stored
Packit Service d40955
 **/
Packit Service d40955
void freeBatchProcessor(BatchProcessor **batchPtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Yield control to the scheduler if the kernel has indicated that
Packit Service d40955
 * other work needs to run on the current processor.
Packit Service d40955
 *
Packit Service d40955
 * The data structure is needed so that the spin lock can be
Packit Service d40955
 * (conditionally) released and re-acquired.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  batch  The batch-processor data
Packit Service d40955
 **/
Packit Service d40955
void condReschedBatchProcessor(BatchProcessor *batch);
Packit Service d40955
Packit Service d40955
#endif // BATCHPROCESSOR_H