Kernel module shows me 8 processors instead of 4 for Intel i5-2500K
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
My question mostly about hardware, specifically the Intel i5-2500K CPU which Intel describes as having
# of Cores 4
# of Threads 4
Linux shows me 4 processors:
$ cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 3
Nevertheless, I've written a little kernel module that shows me 8 processors:
$ cat show_cpus_mod.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/version.h>
#define CLASS_NAME "show_cpus_mod"
#define dbg( format, arg... ) do if ( debug ) pr_info( CLASS_NAME ": %s: " format , __FUNCTION__ , ## arg ); while ( 0 )
#define err( format, arg... ) pr_err( CLASS_NAME ": " format, ## arg )
#define info( format, arg... ) pr_info( CLASS_NAME ": " format, ## arg )
#define warn( format, arg... ) pr_warn( CLASS_NAME ": " format, ## arg )
MODULE_DESCRIPTION( "shows all cpus" );
MODULE_VERSION( "0.1" );
MODULE_LICENSE( "GPL" );
MODULE_AUTHOR( "author <e@mail.mail>" );
static int show_cpus_mod_init( void )
int cpu;
info( "Start loading module show_cpus_mod.n" );
for_each_possible_cpu( cpu )
info( "cpu = %dn", cpu );
return 0;
static void show_cpus_mod_exit( void )
info( "Module show_cpus_mod unloadedn" );
module_init( show_cpus_mod_init );
module_exit( show_cpus_mod_exit );
Building:
$ cat Makefile
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
TARGET = show_cpus_mod
obj-m := $(TARGET).o
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
@rm -f *.o .*.cmd .*.flags *.mod.c *.order
@rm -f .*.*.cmd *.symvers *~ *.*~ TODO.*
@rm -fR .tmp*
@rm -rf .tmp_versions
Inserting:
# make
# cp show_cpus_mod.ko /lib/modules/4.14.0-kali3-amd64/
# depmod
# modprobe show_cpus_mod
syslog:
localhost kernel: [67596.578805] show_cpus_mod: Start loading module show_cpus_mod.
localhost kernel: [67596.578808] show_cpus_mod: cpu = 0
localhost kernel: [67596.578809] show_cpus_mod: cpu = 1
localhost kernel: [67596.578810] show_cpus_mod: cpu = 2
localhost kernel: [67596.578811] show_cpus_mod: cpu = 3
localhost kernel: [67596.578811] show_cpus_mod: cpu = 4
localhost kernel: [67596.578812] show_cpus_mod: cpu = 5
localhost kernel: [67596.578812] show_cpus_mod: cpu = 6
localhost kernel: [67596.578813] show_cpus_mod: cpu = 7
localhost kernel: [67607.725738] show_cpus_mod: Module show_cpus_mod unloaded
What am I missing in Intel's description? Why 8? Or what is wrong with my kernel module?
linux-kernel kernel-modules cpu hardware
New contributor
add a comment |Â
up vote
1
down vote
favorite
My question mostly about hardware, specifically the Intel i5-2500K CPU which Intel describes as having
# of Cores 4
# of Threads 4
Linux shows me 4 processors:
$ cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 3
Nevertheless, I've written a little kernel module that shows me 8 processors:
$ cat show_cpus_mod.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/version.h>
#define CLASS_NAME "show_cpus_mod"
#define dbg( format, arg... ) do if ( debug ) pr_info( CLASS_NAME ": %s: " format , __FUNCTION__ , ## arg ); while ( 0 )
#define err( format, arg... ) pr_err( CLASS_NAME ": " format, ## arg )
#define info( format, arg... ) pr_info( CLASS_NAME ": " format, ## arg )
#define warn( format, arg... ) pr_warn( CLASS_NAME ": " format, ## arg )
MODULE_DESCRIPTION( "shows all cpus" );
MODULE_VERSION( "0.1" );
MODULE_LICENSE( "GPL" );
MODULE_AUTHOR( "author <e@mail.mail>" );
static int show_cpus_mod_init( void )
int cpu;
info( "Start loading module show_cpus_mod.n" );
for_each_possible_cpu( cpu )
info( "cpu = %dn", cpu );
return 0;
static void show_cpus_mod_exit( void )
info( "Module show_cpus_mod unloadedn" );
module_init( show_cpus_mod_init );
module_exit( show_cpus_mod_exit );
Building:
$ cat Makefile
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
TARGET = show_cpus_mod
obj-m := $(TARGET).o
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
@rm -f *.o .*.cmd .*.flags *.mod.c *.order
@rm -f .*.*.cmd *.symvers *~ *.*~ TODO.*
@rm -fR .tmp*
@rm -rf .tmp_versions
Inserting:
# make
# cp show_cpus_mod.ko /lib/modules/4.14.0-kali3-amd64/
# depmod
# modprobe show_cpus_mod
syslog:
localhost kernel: [67596.578805] show_cpus_mod: Start loading module show_cpus_mod.
localhost kernel: [67596.578808] show_cpus_mod: cpu = 0
localhost kernel: [67596.578809] show_cpus_mod: cpu = 1
localhost kernel: [67596.578810] show_cpus_mod: cpu = 2
localhost kernel: [67596.578811] show_cpus_mod: cpu = 3
localhost kernel: [67596.578811] show_cpus_mod: cpu = 4
localhost kernel: [67596.578812] show_cpus_mod: cpu = 5
localhost kernel: [67596.578812] show_cpus_mod: cpu = 6
localhost kernel: [67596.578813] show_cpus_mod: cpu = 7
localhost kernel: [67607.725738] show_cpus_mod: Module show_cpus_mod unloaded
What am I missing in Intel's description? Why 8? Or what is wrong with my kernel module?
linux-kernel kernel-modules cpu hardware
New contributor
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
My question mostly about hardware, specifically the Intel i5-2500K CPU which Intel describes as having
# of Cores 4
# of Threads 4
Linux shows me 4 processors:
$ cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 3
Nevertheless, I've written a little kernel module that shows me 8 processors:
$ cat show_cpus_mod.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/version.h>
#define CLASS_NAME "show_cpus_mod"
#define dbg( format, arg... ) do if ( debug ) pr_info( CLASS_NAME ": %s: " format , __FUNCTION__ , ## arg ); while ( 0 )
#define err( format, arg... ) pr_err( CLASS_NAME ": " format, ## arg )
#define info( format, arg... ) pr_info( CLASS_NAME ": " format, ## arg )
#define warn( format, arg... ) pr_warn( CLASS_NAME ": " format, ## arg )
MODULE_DESCRIPTION( "shows all cpus" );
MODULE_VERSION( "0.1" );
MODULE_LICENSE( "GPL" );
MODULE_AUTHOR( "author <e@mail.mail>" );
static int show_cpus_mod_init( void )
int cpu;
info( "Start loading module show_cpus_mod.n" );
for_each_possible_cpu( cpu )
info( "cpu = %dn", cpu );
return 0;
static void show_cpus_mod_exit( void )
info( "Module show_cpus_mod unloadedn" );
module_init( show_cpus_mod_init );
module_exit( show_cpus_mod_exit );
Building:
$ cat Makefile
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
TARGET = show_cpus_mod
obj-m := $(TARGET).o
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
@rm -f *.o .*.cmd .*.flags *.mod.c *.order
@rm -f .*.*.cmd *.symvers *~ *.*~ TODO.*
@rm -fR .tmp*
@rm -rf .tmp_versions
Inserting:
# make
# cp show_cpus_mod.ko /lib/modules/4.14.0-kali3-amd64/
# depmod
# modprobe show_cpus_mod
syslog:
localhost kernel: [67596.578805] show_cpus_mod: Start loading module show_cpus_mod.
localhost kernel: [67596.578808] show_cpus_mod: cpu = 0
localhost kernel: [67596.578809] show_cpus_mod: cpu = 1
localhost kernel: [67596.578810] show_cpus_mod: cpu = 2
localhost kernel: [67596.578811] show_cpus_mod: cpu = 3
localhost kernel: [67596.578811] show_cpus_mod: cpu = 4
localhost kernel: [67596.578812] show_cpus_mod: cpu = 5
localhost kernel: [67596.578812] show_cpus_mod: cpu = 6
localhost kernel: [67596.578813] show_cpus_mod: cpu = 7
localhost kernel: [67607.725738] show_cpus_mod: Module show_cpus_mod unloaded
What am I missing in Intel's description? Why 8? Or what is wrong with my kernel module?
linux-kernel kernel-modules cpu hardware
New contributor
My question mostly about hardware, specifically the Intel i5-2500K CPU which Intel describes as having
# of Cores 4
# of Threads 4
Linux shows me 4 processors:
$ cat /proc/cpuinfo | grep ^processor
processor : 0
processor : 1
processor : 2
processor : 3
Nevertheless, I've written a little kernel module that shows me 8 processors:
$ cat show_cpus_mod.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/version.h>
#define CLASS_NAME "show_cpus_mod"
#define dbg( format, arg... ) do if ( debug ) pr_info( CLASS_NAME ": %s: " format , __FUNCTION__ , ## arg ); while ( 0 )
#define err( format, arg... ) pr_err( CLASS_NAME ": " format, ## arg )
#define info( format, arg... ) pr_info( CLASS_NAME ": " format, ## arg )
#define warn( format, arg... ) pr_warn( CLASS_NAME ": " format, ## arg )
MODULE_DESCRIPTION( "shows all cpus" );
MODULE_VERSION( "0.1" );
MODULE_LICENSE( "GPL" );
MODULE_AUTHOR( "author <e@mail.mail>" );
static int show_cpus_mod_init( void )
int cpu;
info( "Start loading module show_cpus_mod.n" );
for_each_possible_cpu( cpu )
info( "cpu = %dn", cpu );
return 0;
static void show_cpus_mod_exit( void )
info( "Module show_cpus_mod unloadedn" );
module_init( show_cpus_mod_init );
module_exit( show_cpus_mod_exit );
Building:
$ cat Makefile
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
TARGET = show_cpus_mod
obj-m := $(TARGET).o
default:
$(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
@rm -f *.o .*.cmd .*.flags *.mod.c *.order
@rm -f .*.*.cmd *.symvers *~ *.*~ TODO.*
@rm -fR .tmp*
@rm -rf .tmp_versions
Inserting:
# make
# cp show_cpus_mod.ko /lib/modules/4.14.0-kali3-amd64/
# depmod
# modprobe show_cpus_mod
syslog:
localhost kernel: [67596.578805] show_cpus_mod: Start loading module show_cpus_mod.
localhost kernel: [67596.578808] show_cpus_mod: cpu = 0
localhost kernel: [67596.578809] show_cpus_mod: cpu = 1
localhost kernel: [67596.578810] show_cpus_mod: cpu = 2
localhost kernel: [67596.578811] show_cpus_mod: cpu = 3
localhost kernel: [67596.578811] show_cpus_mod: cpu = 4
localhost kernel: [67596.578812] show_cpus_mod: cpu = 5
localhost kernel: [67596.578812] show_cpus_mod: cpu = 6
localhost kernel: [67596.578813] show_cpus_mod: cpu = 7
localhost kernel: [67607.725738] show_cpus_mod: Module show_cpus_mod unloaded
What am I missing in Intel's description? Why 8? Or what is wrong with my kernel module?
linux-kernel kernel-modules cpu hardware
linux-kernel kernel-modules cpu hardware
New contributor
New contributor
edited Oct 1 at 8:16
Stephen Kitt
149k23329396
149k23329396
New contributor
asked Oct 1 at 8:08
wc1eBdb56TamM
82
82
New contributor
New contributor
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
You should use for_each_online_cpu
or for_each_present_cpu
instead of for_each_possible_cpu
. That will limit the output to CPUs which are really online or present, respectively.
yeah, thanx.possible
is something wrong...
â wc1eBdb56TamM
Oct 1 at 8:20
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You should use for_each_online_cpu
or for_each_present_cpu
instead of for_each_possible_cpu
. That will limit the output to CPUs which are really online or present, respectively.
yeah, thanx.possible
is something wrong...
â wc1eBdb56TamM
Oct 1 at 8:20
add a comment |Â
up vote
3
down vote
accepted
You should use for_each_online_cpu
or for_each_present_cpu
instead of for_each_possible_cpu
. That will limit the output to CPUs which are really online or present, respectively.
yeah, thanx.possible
is something wrong...
â wc1eBdb56TamM
Oct 1 at 8:20
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You should use for_each_online_cpu
or for_each_present_cpu
instead of for_each_possible_cpu
. That will limit the output to CPUs which are really online or present, respectively.
You should use for_each_online_cpu
or for_each_present_cpu
instead of for_each_possible_cpu
. That will limit the output to CPUs which are really online or present, respectively.
answered Oct 1 at 8:15
Stephen Kitt
149k23329396
149k23329396
yeah, thanx.possible
is something wrong...
â wc1eBdb56TamM
Oct 1 at 8:20
add a comment |Â
yeah, thanx.possible
is something wrong...
â wc1eBdb56TamM
Oct 1 at 8:20
yeah, thanx.
possible
is something wrong...â wc1eBdb56TamM
Oct 1 at 8:20
yeah, thanx.
possible
is something wrong...â wc1eBdb56TamM
Oct 1 at 8:20
add a comment |Â
wc1eBdb56TamM is a new contributor. Be nice, and check out our Code of Conduct.
wc1eBdb56TamM is a new contributor. Be nice, and check out our Code of Conduct.
wc1eBdb56TamM is a new contributor. Be nice, and check out our Code of Conduct.
wc1eBdb56TamM is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f472525%2fkernel-module-shows-me-8-processors-instead-of-4-for-intel-i5-2500k%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password