Source
xxxxxxxxxx
/* https://stackoverflow.com/questions/28098082/unable-to-use-more-than-one-processor-group-for-my-threads-in-a-c-sharp-app */
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/* defined in sysinfo lib */
extern int get_cpu_group_num_win32(void);
extern int get_numa_node_num_win32(void);
/* <sys/dkstat.h> removed in OpenBSD 5.7, only <sys/sched.h> with the same CP_* definitions remained */
static zbx_mutex_t cpustats_lock = ZBX_MUTEX_NULL;
static kstat_ctl_t *kc = NULL;
static kid_t kc_id = 0;
static kstat_t *(*ksp)[] = NULL; /* array of pointers to "cpu_stat" elements in kstat chain */
static int refresh_kstat(ZBX_CPUS_STAT_DATA *pcpus)
{
static int cpu_over_count_prev = 0;
int cpu_over_count = 0, i, inserted;
kid_t id;
kstat_t *k;
zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__);
for (i = 0; i < pcpus->count; i++)
(*ksp)[i] = NULL;
/* kstat_chain_update() can return: */
/* - -1 (error), */
/* - a new kstat chain ID (chain successfully updated), */
/* - 0 (kstat chain was up-to-date). We ignore this case to make refresh_kstat() */
/* usable for first-time initialization as the kstat chain is up-to-date after */
/* kstat_open(). */
if (-1 == (id = kstat_chain_update(kc)))
{
zabbix_log(LOG_LEVEL_ERR, "%s: kstat_chain_update() failed", __func__);
return FAIL;
}
if (0 != id)
kc_id = id;
for (k = kc->kc_chain; NULL != k; k = k->ks_next) /* traverse all kstat chain */
{
if (0 == strcmp("cpu_stat", k->ks_module))
{
inserted = 0;
for (i = 1; i <= pcpus->count; i++) /* search in our array of ZBX_SINGLE_CPU_STAT_DATAs */
{
if (pcpus->cpu[i].cpu_num == k->ks_instance) /* CPU instance found */
{
(*ksp)[i - 1] = k;
inserted = 1;
break;