libc/msic:Implement get_nprocs API

Summary:
 1.Remove the macro definition of getnproc in sysinfo
 2.New get_nprocs_conf and get_nprocs interfaces, return CONFIG_SMP_NCPUS, return 1 when not defined

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
This commit is contained in:
chenrun1 2024-07-03 10:14:14 +08:00 committed by Xiang Xiao
parent aa2ae421d5
commit f3cf11dcb5
4 changed files with 91 additions and 10 deletions

View File

@ -33,14 +33,6 @@
#define SI_LOAD_SHIFT 16
#ifdef CONFIG_SMP_NCPUS
#define get_nprocs() CONFIG_SMP_NCPUS
#define get_nprocs_conf() CONFIG_SMP_NCPUS
#else
#define get_nprocs() 1
#define get_nprocs_conf() 1
#endif
/****************************************************************************
* Type Definitions
****************************************************************************/
@ -76,6 +68,8 @@ extern "C"
#endif
int sysinfo(FAR struct sysinfo *info);
int get_nprocs_conf(void);
int get_nprocs(void);
#undef EXTERN
#if defined(__cplusplus)

View File

@ -42,7 +42,8 @@ list(
lib_openat.c
lib_mkdirat.c
lib_utimensat.c
lib_memoryregion.c)
lib_memoryregion.c
lib_getnprocs.c)
# Support for platforms that do not have long long types

View File

@ -25,7 +25,7 @@ CSRCS += lib_xorshift128.c lib_tea_encrypt.c lib_tea_decrypt.c
CSRCS += lib_cxx_initialize.c lib_impure.c lib_memfd.c lib_mutex.c
CSRCS += lib_fchmodat.c lib_fstatat.c lib_getfullpath.c lib_openat.c
CSRCS += lib_mkdirat.c lib_utimensat.c lib_mallopt.c lib_memoryregion.c
CSRCS += lib_idr.c
CSRCS += lib_idr.c lib_getnprocs.c
# Support for platforms that do not have long long types

View File

@ -0,0 +1,86 @@
/****************************************************************************
* libs/libc/misc/lib_getnprocs.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/sysinfo.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: get_nprocs_conf
*
* Description:
* Retrieve the number of configured processors in the system.
* The get_nprocs_conf() function returns the number of processors (CPUs)
* configured in the system, regardless of whether they are currently
* enabled or available. This function is useful for determining the
* processor configuration in multiprocessor systems.
*
* Input Parameters:
* None
*
* Returned Value:
* On success, the number of configured processors is returned.
* If the system does not define a processor configuration, it returns 1.
*
****************************************************************************/
int get_nprocs_conf(void)
{
#ifdef CONFIG_SMP_NCPUS
return CONFIG_SMP_NCPUS;
#else
return 1;
#endif
}
/****************************************************************************
* Name: get_nprocs
*
* Description:
* Retrieve the number of online processors in the system.
* The get_nprocs() function returns the number of processors (CPUs) that
* are currently online and available for use in the system. This function
* can be useful for determining the number of processors that can be used
* by applications or the operating system for parallel processing.
*
* Input Parameters:
* None
*
* Returned Value:
* On success, the number of online processors is returned.
* If the system does not define a processor configuration, it returns 1.
*
****************************************************************************/
int get_nprocs(void)
{
#ifdef CONFIG_SMP_NCPUS
return CONFIG_SMP_NCPUS;
#else
return 1;
#endif
}