Commit 2923cc4c authored by frobinet's avatar frobinet

Add "--enable-cpu-affinity" in build_oai and force affinity to :

- leave CPU0 to the system
- leave CPU1 to HwRxTx thread (I/Q acquisition)
- all other CPUs are left for application threads (CPU2 to CPU7 in 8 core processor configuration)
parent bea23189
......@@ -339,6 +339,10 @@ function main() {
FORCE_DEADLINE_SCHEDULER_FLAG_USER="True"
echo_info "Enabling the usage of deadline scheduler"
shift 1;;
--enable-cpu-affinity)
CPU_AFFINITY_FLAG_USER="True"
echo_info "Enabling CPU Affinity (only valid when not using deadline scheduler)"
shift 1;;
--disable-cpu-affinity)
CPU_AFFINITY_FLAG_USER="False"
echo_info "Disabling CPU Affinity (only valid when not using deadline scheduler)"
......
......@@ -115,8 +115,16 @@ sudo cset shield --reset
cd eur_oai_develop-nr/openairinterface5g/
source oaienv
sudo -E ./cmake_targets/build_oai -c --gNB -w ADRV9371_ZC706 -I
sudo -E ./cmake_targets/build_oai -c --gNB -w ADRV9371_ZC706
sudo -E ./cmake_targets/build_oai -c --gNB -w ADRV9371_ZC706 -I --enable-cpu-affinity
/* CPU available shall be mapped on CPU2 to get_nprocs() number with hyperthreading disabled */
/* because : */
/* - cset shield leave CPU0 for system */
/* - CPU1 is reserved for HwRxTx thread for I/Q acquisition ! */
/* Note: "/usr/local/etc/syriq/cpu-irq.sh" shall be changed if more than 8 cores are used */
/* ie. "cset shield --force --kthread on -c 1-7" where "-c 1-7" reserves CPU1 to CPU7 for application (CPU0 is for system) */
sudo -E ./cmake_targets/build_oai -c --gNB -w ADRV9371_ZC706 --enable-cpu-affinity
......
......@@ -1034,7 +1034,7 @@ int main( int argc, char **argv )
CPU_ZERO(&cpuset);
#ifdef CPU_AFFINITY
if (get_nprocs() > 2) {
CPU_SET(0, &cpuset);
CPU_SET(1, &cpuset);
s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
if (s != 0) {
perror( "pthread_setaffinity_np");
......
......@@ -294,20 +294,32 @@ void thread_top_init(char *thread_name,
char cpu_affinity[1024];
cpu_set_t cpuset;
/* Set affinity mask to include CPUs 1 to MAX_CPUS */
/* Set affinity mask to include CPUs 2 to MAX_CPUS */
/* CPU 0 is reserved for UHD threads */
/* CPU 1 is reserved for all RX_TX threads */
/* Enable CPU Affinity only if number of CPUs >2 */
/* Enable CPU Affinity only if number of CPUs > 2 */
CPU_ZERO(&cpuset);
#ifdef CPU_AFFINITY
if (get_nprocs() > 2)
{
if (affinity == 0)
CPU_SET(0,&cpuset);
{
printf("[SYRTEM CPU AFFINITY !!!] ERROR:affinity is 0 -> 2-7 !!!!!!!!!! !!!!!!!!!!\n");
// CPU_SET(0,&cpuset);
for (j = 2; j < get_nprocs(); j++)
{
CPU_SET(j, &cpuset);
}
}
else
for (j = 1; j < get_nprocs(); j++)
{
for (j = 2; j < get_nprocs(); j++)
{
CPU_SET(j, &cpuset);
}
}
s = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
if (s != 0)
{
......@@ -319,17 +331,21 @@ void thread_top_init(char *thread_name,
/* Check the actual affinity mask assigned to the thread */
s = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
if (s != 0) {
if (s != 0)
{
perror( "pthread_getaffinity_np");
exit_fun("Error getting processor affinity ");
}
memset(cpu_affinity,0,sizeof(cpu_affinity));
for (j = 0; j < 1024; j++)
if (CPU_ISSET(j, &cpuset)) {
{
if (CPU_ISSET(j, &cpuset))
{
char temp[1024];
sprintf (temp, " CPU_%d", j);
strcat(cpu_affinity, temp);
}
}
memset(&sparam, 0, sizeof(sparam));
sparam.sched_priority = sched_get_priority_max(SCHED_FIFO);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment