merge fix_lscpu into 6.0.0

【回合 600】修复 24.03 通过 lscpu 获取 CPU 数量有误的问题

Created-by: bomou
Commit-by: bomou
Merged-by: opengauss_bot
Description: 【标题】

【回合 600】修复 24.03 通过 lscpu 获取 CPU 数量有误的问题

【实现内容】

修复 24.03 通过 lscpu 获取 CPU 数量有误的问题

【根因分析】

回合 pr:https://gitcode.com/opengauss/openGauss-server/pull/7720

【实现方案】

回合 pr:https://gitcode.com/opengauss/openGauss-server/pull/7720

【关联需求或issue】

https://gitcode.com/opengauss/openGauss-server/issues/6981

【开发自验报告】

GUC 参数:

```conf
enable_thread_pool = on
thread_pool_attr = '200,2,(cpubind:1-60, 250-255)'
```

将 guc 配置为边界值,启动成功:

![image.png](https://raw.gitcode.com/user-images/assets/5089689/11358405-425c-45c2-bf22-9c636cec6af8/image.png 'image.png')

构造异常 guc 参数,启动失败

![image.png](https://raw.gitcode.com/user-images/assets/5089689/84385603-a0a6-4550-99e1-dd0273e6a55e/image.png 'image.png')


See merge request: opengauss/openGauss-server!7874
This commit is contained in:
opengauss_bot
2025-06-10 16:26:54 +08:00

View File

@ -58,6 +58,8 @@
#include "communication/commproxy_interface.h"
#include "utils/mem_snapshot.h"
#include <thread>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
@ -590,16 +592,13 @@ void ThreadPoolControler::GetCpuAndNumaNum(int32 *totalCpuNum, int32 *totalNumaN
{
char buf[BUFSIZE];
*totalCpuNum = std::thread::hardware_concurrency();
FILE* fp = NULL;
if ((fp = popen("LANGUAGE=en_US.UTF-8;LANG=en_US.UTF-8;lscpu", "r")) != NULL) {
while (fgets(buf, sizeof(buf), fp) != NULL) {
if (strncmp("CPU(s)", buf, strlen("CPU(s)")) == 0 &&
strncmp("On-line CPU(s) list", buf, strlen("On-line CPU(s) list")) != 0 &&
strncmp("NUMA node", buf, strlen("NUMA node")) != 0) {
char* loc = strchr(buf, ':');
*totalCpuNum = pg_strtoint32(loc + 1);
} else if (strncmp("NUMA node(s)", buf, strlen("NUMA node(s)")) == 0) {
if (strncmp("NUMA node(s)", buf, strlen("NUMA node(s)")) == 0) {
char* loc = strchr(buf, ':');
*totalNumaNum = pg_strtoint32(loc + 1);
}