From 31d45d0d8ee1d8eee96fc2a283a388b6b6aca669 Mon Sep 17 00:00:00 2001 From: Damien Zammit Date: Sun, 24 Sep 2023 10:34:49 +0000 Subject: cpu_number: Inline widely used simple function TESTED: on uniprocessor and smp, both behaved as normal. Message-Id: <20230924103428.455966-2-damien@zamaudio.com> --- i386/Makefrag_x86.am | 1 - i386/i386/cpu_number.c | 30 ------------------------------ i386/i386/cpu_number.h | 10 ++++++++-- kern/ast.h | 1 - kern/processor.h | 3 ++- kern/thread.h | 3 ++- 6 files changed, 12 insertions(+), 36 deletions(-) delete mode 100644 i386/i386/cpu_number.c diff --git a/i386/Makefrag_x86.am b/i386/Makefrag_x86.am index 46c1d38b..272de023 100644 --- a/i386/Makefrag_x86.am +++ b/i386/Makefrag_x86.am @@ -18,7 +18,6 @@ libkernel_a_SOURCES += \ i386/i386/ast_check.c \ i386/i386/ast_types.h \ i386/i386/cpu.h \ - i386/i386/cpu_number.c \ i386/i386/cpu_number.h \ i386/i386/db_disasm.c \ i386/i386/db_interface.c \ diff --git a/i386/i386/cpu_number.c b/i386/i386/cpu_number.c deleted file mode 100644 index ef19e11f..00000000 --- a/i386/i386/cpu_number.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 Free Software Foundation, Inc. - * - * 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, see . - */ - -#include -#include -#include -#include -#include -#include - -#if NCPUS > 1 -int cpu_number(void) -{ - return cpu_id_lut[apic_get_current_cpu()]; -} -#endif diff --git a/i386/i386/cpu_number.h b/i386/i386/cpu_number.h index 479a847a..8357be84 100644 --- a/i386/i386/cpu_number.h +++ b/i386/i386/cpu_number.h @@ -64,8 +64,14 @@ popl %esi ;\ #ifndef __ASSEMBLER__ -#include "kern/cpu_number.h" -int cpu_number(void); +#include +#include + +static inline int cpu_number(void) +{ + return cpu_id_lut[apic_get_current_cpu()]; +} + #endif #else /* NCPUS == 1 */ diff --git a/kern/ast.h b/kern/ast.h index c8cbd04f..aded1677 100644 --- a/kern/ast.h +++ b/kern/ast.h @@ -40,7 +40,6 @@ * a set of reasons for an AST, and passing this set to ast_taken. */ -#include "cpu_number.h" #include #include #include diff --git a/kern/processor.h b/kern/processor.h index 17b784a3..79386627 100644 --- a/kern/processor.h +++ b/kern/processor.h @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include @@ -112,6 +111,8 @@ struct processor { typedef struct processor Processor; extern struct processor processor_array[NCPUS]; +#include + /* * Chain of all processor sets. */ diff --git a/kern/thread.h b/kern/thread.h index 8547464d..bf07828a 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -235,6 +234,8 @@ struct thread { #endif }; +#include + /* typedef of thread_t is in kern/kern_types.h */ typedef struct thread_shuttle *thread_shuttle_t; #define THREAD_NULL ((thread_t) 0) -- cgit v1.2.3