From 2bb91ab4daa891aeaf6dc84b468ef9f030edd742 Mon Sep 17 00:00:00 2001 From: visa Date: Thu, 18 Jan 2018 14:02:54 +0000 Subject: [PATCH] Fix the computation of `ncpusfound' on !MULTIPROCESSOR kernels so that the value matches with the number of cores that GENERIC.MP uses. OK deraadt@, krw@, pirofti@ --- sys/arch/octeon/include/cpu.h | 7 +++++-- sys/arch/octeon/octeon/machdep.c | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/sys/arch/octeon/include/cpu.h b/sys/arch/octeon/include/cpu.h index b07539bef81..afc9a037a92 100644 --- a/sys/arch/octeon/include/cpu.h +++ b/sys/arch/octeon/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.10 2017/07/30 16:08:09 visa Exp $ */ +/* $OpenBSD: cpu.h,v 1.11 2018/01/18 14:02:54 visa Exp $ */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -45,8 +45,11 @@ #define _MACHINE_CPU_H_ #ifdef _KERNEL + +#define OCTEON_MAXCPUS 16 + #if defined(MULTIPROCESSOR) && !defined(_LOCORE) -#define MAXCPUS 16 +#define MAXCPUS OCTEON_MAXCPUS struct cpu_info; struct cpu_info *hw_getcurcpu(void); void hw_setcurcpu(struct cpu_info *); diff --git a/sys/arch/octeon/octeon/machdep.c b/sys/arch/octeon/octeon/machdep.c index 631cec0535a..1e18fec5ad8 100644 --- a/sys/arch/octeon/octeon/machdep.c +++ b/sys/arch/octeon/octeon/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.103 2017/12/30 20:46:59 guenther Exp $ */ +/* $OpenBSD: machdep.c,v 1.104 2018/01/18 14:02:54 visa Exp $ */ /* * Copyright (c) 2009, 2010 Miodrag Vallat. @@ -681,11 +681,11 @@ get_ncpusfound(void) { extern struct boot_desc *octeon_boot_desc; uint64_t core_mask = octeon_boot_desc->core_mask; - uint64_t i, m, ncpus = 0; + uint64_t i, ncpus = 0; - for (i = 0, m = 1 ; i < MAXCPUS; i++, m <<= 1) - if (core_mask & m) - ncpus++; + /* There has to be 1-to-1 mapping between cpuids and coreids. */ + for (i = 0; i < OCTEON_MAXCPUS && (core_mask & (1ul << i)) != 0; i++) + ncpus++; return ncpus; } -- 2.20.1