Blame source/vdo/base/threadConfig.h

Packit Service 7e342f
/*
Packit Service 7e342f
 * Copyright (c) 2020 Red Hat, Inc.
Packit Service 7e342f
 *
Packit Service 7e342f
 * This program is free software; you can redistribute it and/or
Packit Service 7e342f
 * modify it under the terms of the GNU General Public License
Packit Service 7e342f
 * as published by the Free Software Foundation; either version 2
Packit Service 7e342f
 * of the License, or (at your option) any later version.
Packit Service 7e342f
 * 
Packit Service 7e342f
 * This program is distributed in the hope that it will be useful,
Packit Service 7e342f
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 7e342f
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service 7e342f
 * GNU General Public License for more details.
Packit Service 7e342f
 * 
Packit Service 7e342f
 * You should have received a copy of the GNU General Public License
Packit Service 7e342f
 * along with this program; if not, write to the Free Software
Packit Service 7e342f
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit Service 7e342f
 * 02110-1301, USA. 
Packit Service 7e342f
 *
Packit Service 7e342f
 * $Id: //eng/vdo-releases/aluminum/src/c++/vdo/base/threadConfig.h#1 $
Packit Service 7e342f
 */
Packit Service 7e342f
Packit Service 7e342f
#ifndef THREAD_CONFIG_H
Packit Service 7e342f
#define THREAD_CONFIG_H
Packit Service 7e342f
Packit Service 7e342f
#include "permassert.h"
Packit Service 7e342f
Packit Service 7e342f
#include "types.h"
Packit Service 7e342f
Packit Service 7e342f
struct threadConfig {
Packit Service 7e342f
  ZoneCount    logicalZoneCount;
Packit Service 7e342f
  ZoneCount    physicalZoneCount;
Packit Service 7e342f
  ZoneCount    hashZoneCount;
Packit Service 7e342f
  ThreadCount  baseThreadCount;
Packit Service 7e342f
  ThreadID     adminThread;
Packit Service 7e342f
  ThreadID     journalThread;
Packit Service 7e342f
  ThreadID     packerThread;
Packit Service 7e342f
  ThreadID    *logicalThreads;
Packit Service 7e342f
  ThreadID    *physicalThreads;
Packit Service 7e342f
  ThreadID    *hashZoneThreads;
Packit Service 7e342f
};
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Make a thread configuration. If both the logical zone count and the
Packit Service 7e342f
 * physical zone count are set to 0, a one thread configuration will be
Packit Service 7e342f
 * made.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param [in]  logicalZoneCount    The number of logical zones
Packit Service 7e342f
 * @param [in]  physicalZoneCount   The number of physical zones
Packit Service 7e342f
 * @param [in]  hashZoneCount       The number of hash zones
Packit Service 7e342f
 * @param [out] configPtr           A pointer to hold the new thread
Packit Service 7e342f
 *                                  configuration
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return VDO_SUCCESS or an error
Packit Service 7e342f
 **/
Packit Service 7e342f
int makeThreadConfig(ZoneCount      logicalZoneCount,
Packit Service 7e342f
                     ZoneCount      physicalZoneCount,
Packit Service 7e342f
                     ZoneCount      hashZoneCount,
Packit Service 7e342f
                     ThreadConfig **configPtr)
Packit Service 7e342f
  __attribute__((warn_unused_result));
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Make a thread configuration that uses no threads. This is the configuration
Packit Service 7e342f
 * for VDOs which are constructed from user mode that have only a synchronous
Packit Service 7e342f
 * layer.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param [out] configPtr   A pointer to hold the new thread configuration
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return VDO_SUCCESS or an error
Packit Service 7e342f
 **/
Packit Service 7e342f
int makeZeroThreadConfig(ThreadConfig **configPtr);
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Make a thread configuration that uses only one thread.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param [out] configPtr      A pointer to hold the new thread configuration
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return VDO_SUCCESS or an error
Packit Service 7e342f
 **/
Packit Service 7e342f
int makeOneThreadConfig(ThreadConfig **configPtr)
Packit Service 7e342f
  __attribute__((warn_unused_result));
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Make a new thread config which is a copy of an existing one.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param [in]  oldConfig       The thread configuration to copy
Packit Service 7e342f
 * @param [out] configPtr       A pointer to hold the new thread configuration
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return VDO_SUCCESS or an error
Packit Service 7e342f
 **/
Packit Service 7e342f
int copyThreadConfig(const ThreadConfig *oldConfig, ThreadConfig **configPtr)
Packit Service 7e342f
  __attribute__((warn_unused_result));
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Destroy a thread configuration and null out the reference to it.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param configPtr  The reference to the thread configuration to destroy
Packit Service 7e342f
 **/
Packit Service 7e342f
void freeThreadConfig(ThreadConfig **configPtr);
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Get the thread id for a given logical zone.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  the thread config
Packit Service 7e342f
 * @param logicalZone   the number of the logical zone
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return the thread id for the given zone
Packit Service 7e342f
 **/
Packit Service 7e342f
__attribute__((warn_unused_result))
Packit Service 7e342f
static inline ThreadID getLogicalZoneThread(const ThreadConfig *threadConfig,
Packit Service 7e342f
                                            ZoneCount           logicalZone)
Packit Service 7e342f
{
Packit Service 7e342f
  ASSERT_LOG_ONLY((logicalZone <= threadConfig->logicalZoneCount),
Packit Service 7e342f
                  "logical zone valid");
Packit Service 7e342f
  return threadConfig->logicalThreads[logicalZone];
Packit Service 7e342f
}
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Get the thread id for a given physical zone.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  the thread config
Packit Service 7e342f
 * @param physicalZone  the number of the physical zone
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return the thread id for the given zone
Packit Service 7e342f
 **/
Packit Service 7e342f
__attribute__((warn_unused_result))
Packit Service 7e342f
static inline ThreadID getPhysicalZoneThread(const ThreadConfig *threadConfig,
Packit Service 7e342f
                                             ZoneCount           physicalZone)
Packit Service 7e342f
{
Packit Service 7e342f
  ASSERT_LOG_ONLY((physicalZone <= threadConfig->physicalZoneCount),
Packit Service 7e342f
                  "physical zone valid");
Packit Service 7e342f
  return threadConfig->physicalThreads[physicalZone];
Packit Service 7e342f
}
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Get the thread id for a given hash zone.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  the thread config
Packit Service 7e342f
 * @param hashZone      the number of the hash zone
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return the thread id for the given zone
Packit Service 7e342f
 **/
Packit Service 7e342f
__attribute__((warn_unused_result))
Packit Service 7e342f
static inline ThreadID getHashZoneThread(const ThreadConfig *threadConfig,
Packit Service 7e342f
                                         ZoneCount           hashZone)
Packit Service 7e342f
{
Packit Service 7e342f
  ASSERT_LOG_ONLY((hashZone <= threadConfig->hashZoneCount),
Packit Service 7e342f
                  "hash zone valid");
Packit Service 7e342f
  return threadConfig->hashZoneThreads[hashZone];
Packit Service 7e342f
}
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Get the thread id for the journal zone.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  the thread config
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return the thread id for the journal zone
Packit Service 7e342f
 **/
Packit Service 7e342f
__attribute__((warn_unused_result))
Packit Service 7e342f
static inline ThreadID getJournalZoneThread(const ThreadConfig *threadConfig)
Packit Service 7e342f
{
Packit Service 7e342f
  return threadConfig->journalThread;
Packit Service 7e342f
}
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Get the thread id for the packer zone.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  the thread config
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return the thread id for the packer zone
Packit Service 7e342f
 **/
Packit Service 7e342f
__attribute__((warn_unused_result))
Packit Service 7e342f
static inline ThreadID getPackerZoneThread(const ThreadConfig *threadConfig)
Packit Service 7e342f
{
Packit Service 7e342f
  return threadConfig->packerThread;
Packit Service 7e342f
}
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Get the thread ID for admin requests.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  The thread config
Packit Service 7e342f
 *
Packit Service 7e342f
 * @return the thread id to use for admin requests
Packit Service 7e342f
 **/
Packit Service 7e342f
__attribute__((warn_unused_result))
Packit Service 7e342f
static inline ThreadID getAdminThread(const ThreadConfig *threadConfig)
Packit Service 7e342f
{
Packit Service 7e342f
  return threadConfig->adminThread;
Packit Service 7e342f
}
Packit Service 7e342f
Packit Service 7e342f
/**
Packit Service 7e342f
 * Format the name of the worker thread desired to support a given
Packit Service 7e342f
 * work queue. The physical layer may add a prefix identifying the
Packit Service 7e342f
 * product; the output from this function should just identify the
Packit Service 7e342f
 * thread.
Packit Service 7e342f
 *
Packit Service 7e342f
 * @param threadConfig  The thread configuration
Packit Service 7e342f
 * @param threadID      The thread id
Packit Service 7e342f
 * @param buffer        Where to put the formatted name
Packit Service 7e342f
 * @param bufferLength  Size of the output buffer
Packit Service 7e342f
 **/
Packit Service 7e342f
void getVDOThreadName(const ThreadConfig *threadConfig,
Packit Service 7e342f
                      ThreadID            threadID,
Packit Service 7e342f
                      char               *buffer,
Packit Service 7e342f
                      size_t              bufferLength);
Packit Service 7e342f
Packit Service 7e342f
#endif /* THREAD_CONFIG_H */