Blame source/vdo/base/threadConfig.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/base/threadConfig.h#1 $
Packit Service d40955
 */
Packit Service d40955
Packit Service d40955
#ifndef THREAD_CONFIG_H
Packit Service d40955
#define THREAD_CONFIG_H
Packit Service d40955
Packit Service d40955
#include "permassert.h"
Packit Service d40955
Packit Service d40955
#include "types.h"
Packit Service d40955
Packit Service d40955
struct threadConfig {
Packit Service d40955
  ZoneCount    logicalZoneCount;
Packit Service d40955
  ZoneCount    physicalZoneCount;
Packit Service d40955
  ZoneCount    hashZoneCount;
Packit Service d40955
  ThreadCount  baseThreadCount;
Packit Service d40955
  ThreadID     adminThread;
Packit Service d40955
  ThreadID     journalThread;
Packit Service d40955
  ThreadID     packerThread;
Packit Service d40955
  ThreadID    *logicalThreads;
Packit Service d40955
  ThreadID    *physicalThreads;
Packit Service d40955
  ThreadID    *hashZoneThreads;
Packit Service d40955
};
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Make a thread configuration. If both the logical zone count and the
Packit Service d40955
 * physical zone count are set to 0, a one thread configuration will be
Packit Service d40955
 * made.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  logicalZoneCount    The number of logical zones
Packit Service d40955
 * @param [in]  physicalZoneCount   The number of physical zones
Packit Service d40955
 * @param [in]  hashZoneCount       The number of hash zones
Packit Service d40955
 * @param [out] configPtr           A pointer to hold the new thread
Packit Service d40955
 *                                  configuration
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or an error
Packit Service d40955
 **/
Packit Service d40955
int makeThreadConfig(ZoneCount      logicalZoneCount,
Packit Service d40955
                     ZoneCount      physicalZoneCount,
Packit Service d40955
                     ZoneCount      hashZoneCount,
Packit Service d40955
                     ThreadConfig **configPtr)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Make a thread configuration that uses no threads. This is the configuration
Packit Service d40955
 * for VDOs which are constructed from user mode that have only a synchronous
Packit Service d40955
 * layer.
Packit Service d40955
 *
Packit Service d40955
 * @param [out] configPtr   A pointer to hold the new thread configuration
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or an error
Packit Service d40955
 **/
Packit Service d40955
int makeZeroThreadConfig(ThreadConfig **configPtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Make a thread configuration that uses only one thread.
Packit Service d40955
 *
Packit Service d40955
 * @param [out] configPtr      A pointer to hold the new thread configuration
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or an error
Packit Service d40955
 **/
Packit Service d40955
int makeOneThreadConfig(ThreadConfig **configPtr)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Make a new thread config which is a copy of an existing one.
Packit Service d40955
 *
Packit Service d40955
 * @param [in]  oldConfig       The thread configuration to copy
Packit Service d40955
 * @param [out] configPtr       A pointer to hold the new thread configuration
Packit Service d40955
 *
Packit Service d40955
 * @return VDO_SUCCESS or an error
Packit Service d40955
 **/
Packit Service d40955
int copyThreadConfig(const ThreadConfig *oldConfig, ThreadConfig **configPtr)
Packit Service d40955
  __attribute__((warn_unused_result));
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Destroy a thread configuration and null out the reference to it.
Packit Service d40955
 *
Packit Service d40955
 * @param configPtr  The reference to the thread configuration to destroy
Packit Service d40955
 **/
Packit Service d40955
void freeThreadConfig(ThreadConfig **configPtr);
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the thread id for a given logical zone.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  the thread config
Packit Service d40955
 * @param logicalZone   the number of the logical zone
Packit Service d40955
 *
Packit Service d40955
 * @return the thread id for the given zone
Packit Service d40955
 **/
Packit Service d40955
__attribute__((warn_unused_result))
Packit Service d40955
static inline ThreadID getLogicalZoneThread(const ThreadConfig *threadConfig,
Packit Service d40955
                                            ZoneCount           logicalZone)
Packit Service d40955
{
Packit Service d40955
  ASSERT_LOG_ONLY((logicalZone <= threadConfig->logicalZoneCount),
Packit Service d40955
                  "logical zone valid");
Packit Service d40955
  return threadConfig->logicalThreads[logicalZone];
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the thread id for a given physical zone.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  the thread config
Packit Service d40955
 * @param physicalZone  the number of the physical zone
Packit Service d40955
 *
Packit Service d40955
 * @return the thread id for the given zone
Packit Service d40955
 **/
Packit Service d40955
__attribute__((warn_unused_result))
Packit Service d40955
static inline ThreadID getPhysicalZoneThread(const ThreadConfig *threadConfig,
Packit Service d40955
                                             ZoneCount           physicalZone)
Packit Service d40955
{
Packit Service d40955
  ASSERT_LOG_ONLY((physicalZone <= threadConfig->physicalZoneCount),
Packit Service d40955
                  "physical zone valid");
Packit Service d40955
  return threadConfig->physicalThreads[physicalZone];
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the thread id for a given hash zone.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  the thread config
Packit Service d40955
 * @param hashZone      the number of the hash zone
Packit Service d40955
 *
Packit Service d40955
 * @return the thread id for the given zone
Packit Service d40955
 **/
Packit Service d40955
__attribute__((warn_unused_result))
Packit Service d40955
static inline ThreadID getHashZoneThread(const ThreadConfig *threadConfig,
Packit Service d40955
                                         ZoneCount           hashZone)
Packit Service d40955
{
Packit Service d40955
  ASSERT_LOG_ONLY((hashZone <= threadConfig->hashZoneCount),
Packit Service d40955
                  "hash zone valid");
Packit Service d40955
  return threadConfig->hashZoneThreads[hashZone];
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the thread id for the journal zone.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  the thread config
Packit Service d40955
 *
Packit Service d40955
 * @return the thread id for the journal zone
Packit Service d40955
 **/
Packit Service d40955
__attribute__((warn_unused_result))
Packit Service d40955
static inline ThreadID getJournalZoneThread(const ThreadConfig *threadConfig)
Packit Service d40955
{
Packit Service d40955
  return threadConfig->journalThread;
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the thread id for the packer zone.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  the thread config
Packit Service d40955
 *
Packit Service d40955
 * @return the thread id for the packer zone
Packit Service d40955
 **/
Packit Service d40955
__attribute__((warn_unused_result))
Packit Service d40955
static inline ThreadID getPackerZoneThread(const ThreadConfig *threadConfig)
Packit Service d40955
{
Packit Service d40955
  return threadConfig->packerThread;
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Get the thread ID for admin requests.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  The thread config
Packit Service d40955
 *
Packit Service d40955
 * @return the thread id to use for admin requests
Packit Service d40955
 **/
Packit Service d40955
__attribute__((warn_unused_result))
Packit Service d40955
static inline ThreadID getAdminThread(const ThreadConfig *threadConfig)
Packit Service d40955
{
Packit Service d40955
  return threadConfig->adminThread;
Packit Service d40955
}
Packit Service d40955
Packit Service d40955
/**
Packit Service d40955
 * Format the name of the worker thread desired to support a given
Packit Service d40955
 * work queue. The physical layer may add a prefix identifying the
Packit Service d40955
 * product; the output from this function should just identify the
Packit Service d40955
 * thread.
Packit Service d40955
 *
Packit Service d40955
 * @param threadConfig  The thread configuration
Packit Service d40955
 * @param threadID      The thread id
Packit Service d40955
 * @param buffer        Where to put the formatted name
Packit Service d40955
 * @param bufferLength  Size of the output buffer
Packit Service d40955
 **/
Packit Service d40955
void getVDOThreadName(const ThreadConfig *threadConfig,
Packit Service d40955
                      ThreadID            threadID,
Packit Service d40955
                      char               *buffer,
Packit Service d40955
                      size_t              bufferLength);
Packit Service d40955
Packit Service d40955
#endif /* THREAD_CONFIG_H */