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