Linux CPU Ethereum
Publish: 2021-05-21 11:40:36
1.
How to use the Linux system mining, to use the service of the HA Yu miner, only need two steps, you can mine on the Linux system
-
open the website, input the mobile phone number, select how many CPUs you want to use for mining, the default is to use 50% of the CPU for mining, click to generate your exclusive command and
in two steps, you can mine on Linux system, the money you dig only needs to go to the website of hayu miner, enter your mobile phone number to withdraw< br />
2. Mining doesn't need a good CPU, does it? CPU algorithm mining is too low, mining is mainly using graphics card mining
3. It has nothing to do with ruipin
the CPU utilization of Linux is calculated according to a single core. If the process supports multithreading, it can occupy multiple cores, and it is normal for a single process to exceed 100%. However, if the server itself has no load and the CPU utilization of a single process or many processes exceeds 100%, you need to check the reason. The picture doesn't look like a big problem, and you've erased the process command information.
the CPU utilization of Linux is calculated according to a single core. If the process supports multithreading, it can occupy multiple cores, and it is normal for a single process to exceed 100%. However, if the server itself has no load and the CPU utilization of a single process or many processes exceeds 100%, you need to check the reason. The picture doesn't look like a big problem, and you've erased the process command information.
4. CPU is not developed for windows. CPU to take out is not limited to the PC platform. A successful development of a CPU architecture can generate many sub versions, which are used in different hardware, but they do not all have win. CPU to take out, the premise is that the CPU hardware is compatible with modern operating systems, Linux is one of them
otherwise no software can run on it, who will buy your CPU
the published details are limited to the parts related to the operating system, and the instruction set itself must be disclosed. If it is not disclosed, there will be no operating system running on the CPU, and it will be useless
linux is just a kernel platform. Arm also needs a platform to run when testing processor. So its own developers will also port Linux< Why isn't win compatible with other processors? Because Microsoft wants to sell its own hardware and software at the same time. Its system is for sale. The technology world has suffered a lot from Microsoft. Linux is available to all. If you want to buy a computer, you have to buy someone's software. Does the software seller have the advantage of raising the price at will? In the past, we all suffered from Microsoft's losses, and we all tried to be compatible with Microsoft's system. In the end, we all asked Microsoft to give us a high hand. The current enterprise strategy is that the system should be independent, and the best candidate is Linux.
otherwise no software can run on it, who will buy your CPU
the published details are limited to the parts related to the operating system, and the instruction set itself must be disclosed. If it is not disclosed, there will be no operating system running on the CPU, and it will be useless
linux is just a kernel platform. Arm also needs a platform to run when testing processor. So its own developers will also port Linux< Why isn't win compatible with other processors? Because Microsoft wants to sell its own hardware and software at the same time. Its system is for sale. The technology world has suffered a lot from Microsoft. Linux is available to all. If you want to buy a computer, you have to buy someone's software. Does the software seller have the advantage of raising the price at will? In the past, we all suffered from Microsoft's losses, and we all tried to be compatible with Microsoft's system. In the end, we all asked Microsoft to give us a high hand. The current enterprise strategy is that the system should be independent, and the best candidate is Linux.
5. Information in cat / proc / cpuinfo
ID of processor logic processor
physical id the ID of the physically encapsulated processor
core id the ID of each core
the number of CPU cores in the same physical package
siblings the number of logical processors in the same physical package
1 view the number of physical CPUs
#cat / proc / cpuinfo | grep & quot; physical id"| Sort | uniq | WC – l
2. View the number of logical CPUs
# cat / Pro / cpuinfo | grep & quot; processor"| WC – l
3. How many cores is the CPU; cores"| Uniq
4. View the main frequency of CPU
#cat / proc / cpuinfo | grep MHz | uniq
5, # uname - a
6, Linux euis1 2.6.9-55.elsmp # 1 SMP fri APR 20 17:03:35 EDT 2007 i686 i686 i386 GNU / Linux
(view the current operating system kernel information)
7, # cat / etc / issue | grep Linux
8 Red Hat Enterprise Linux as release 4 (Nahant update 5)
9, # cat / proc / cpuinfo | grep name | cut - F2 - D: | uniq - C
8 Intel (R) Xeon (R) CPU E5410 @ 2.33ghz
(you can see that there are 8 logical CPUs, Also know the CPU model)
9 # cat / proc / cpuinfo | grep physical | uniq - C
4 physical ID: 0
4 physical ID: 1
(indicating that it is actually two 4-core CPUs)
10, # getconf long_ Bit
32
(indicating that the current CPU is running in 32bit mode, but it does not mean that the CPU does not support 64bit)
11, # cat / Pro / cpuinfo | grep flags | grep & # 39; lm ' | WC – l
8 (if the result is greater than 0, it means 64bit computing is supported. LM means long mode, and LM means 64bit)
12. How to get CPU details:
linux command: cat / proc / cpuinfo
13. Use the command to judge several physical CPUs and cores:
number of logical CPUs:
# cat / proc / cpuinfo | grep & quot; processor" | WC - L
number of physical CPUs:
# cat / proc / cpuinfo | grep & quot; physical id" | Sort | uniq | WC - L
14. The number of cores in each physical CPU:
# cat / Pro / cpuinfo | grep & quot; cpu cores" | WC - L
15. Is it a hyper thread? If two logical CPUs have the same "core ID", then the hyperthread is turned on. The number of logical CPUs (core, threads or both) in each physical CPU:
# cat / Pro / cpuinfo | grep & quot; siblings"<
1. View CPU information command
cat / Pro / cpuinfo
2. View memory information command
cat / Pro / meminfo
3. View hard disk information command
fdisk - L
View CPU information (model)
# cat / Pro / cpuinfo | grep name | cut - F2 - D: | uniq - C
8 Intel (R) Xeon (R) CPU E5410 @ 2.33ghz
(see There are 8 logical CPUs, and we also know the CPU model)
# cat / proc / cpuinfo | grep physical | uniq - C
4 physical ID: 0
4 physical ID: 1
(indicating that it is actually two 4-core CPUs)
PS: Jay added on 10th, may, 2011
# in fact, there may be hyper threading HT Technology, not necessarily 4-core, but 2-core 4-thread; At that time, I didn't understand clearly
? Getconf long_ Bit
32
(indicating that the current CPU is running in 32bit mode, but it does not mean that the CPU does not support 64bit)
# cat / Pro / cpuinfo | grep flags | grep & # 39; lm ' | WC - L
8
(the result is greater than 0, which indicates that 64bit computing is supported. LM means long mode, while LM means 64bit)
let's look at the details of CPU, but most of us don't care about it.
? Dmidecode | grep # 39; Processor Information'
view memory information
# cat / proc / meminfo
# uname - a
linux euis1 2.6.9-55.elsmp # 1 SMP fri APR 20 17:03:35 EDT 2007 i686 i686 i386 GNU / Linux
(view current operating system kernel information)
# cat / etc / issue | grep Linux
Red Hat Enterprise Linux as release 4 (Nahant update 5)
(view current operating system kernel information)
# cat / etc / issue | grep Linux Release information)
view the machine model
? Dmidecode | grep & quot; Proct Name"
View network card information
# dmesg | grep - I eth
ID of processor logic processor
physical id the ID of the physically encapsulated processor
core id the ID of each core
the number of CPU cores in the same physical package
siblings the number of logical processors in the same physical package
1 view the number of physical CPUs
#cat / proc / cpuinfo | grep & quot; physical id"| Sort | uniq | WC – l
2. View the number of logical CPUs
# cat / Pro / cpuinfo | grep & quot; processor"| WC – l
3. How many cores is the CPU; cores"| Uniq
4. View the main frequency of CPU
#cat / proc / cpuinfo | grep MHz | uniq
5, # uname - a
6, Linux euis1 2.6.9-55.elsmp # 1 SMP fri APR 20 17:03:35 EDT 2007 i686 i686 i386 GNU / Linux
(view the current operating system kernel information)
7, # cat / etc / issue | grep Linux
8 Red Hat Enterprise Linux as release 4 (Nahant update 5)
9, # cat / proc / cpuinfo | grep name | cut - F2 - D: | uniq - C
8 Intel (R) Xeon (R) CPU E5410 @ 2.33ghz
(you can see that there are 8 logical CPUs, Also know the CPU model)
9 # cat / proc / cpuinfo | grep physical | uniq - C
4 physical ID: 0
4 physical ID: 1
(indicating that it is actually two 4-core CPUs)
10, # getconf long_ Bit
32
(indicating that the current CPU is running in 32bit mode, but it does not mean that the CPU does not support 64bit)
11, # cat / Pro / cpuinfo | grep flags | grep & # 39; lm ' | WC – l
8 (if the result is greater than 0, it means 64bit computing is supported. LM means long mode, and LM means 64bit)
12. How to get CPU details:
linux command: cat / proc / cpuinfo
13. Use the command to judge several physical CPUs and cores:
number of logical CPUs:
# cat / proc / cpuinfo | grep & quot; processor" | WC - L
number of physical CPUs:
# cat / proc / cpuinfo | grep & quot; physical id" | Sort | uniq | WC - L
14. The number of cores in each physical CPU:
# cat / Pro / cpuinfo | grep & quot; cpu cores" | WC - L
15. Is it a hyper thread? If two logical CPUs have the same "core ID", then the hyperthread is turned on. The number of logical CPUs (core, threads or both) in each physical CPU:
# cat / Pro / cpuinfo | grep & quot; siblings"<
1. View CPU information command
cat / Pro / cpuinfo
2. View memory information command
cat / Pro / meminfo
3. View hard disk information command
fdisk - L
View CPU information (model)
# cat / Pro / cpuinfo | grep name | cut - F2 - D: | uniq - C
8 Intel (R) Xeon (R) CPU E5410 @ 2.33ghz
(see There are 8 logical CPUs, and we also know the CPU model)
# cat / proc / cpuinfo | grep physical | uniq - C
4 physical ID: 0
4 physical ID: 1
(indicating that it is actually two 4-core CPUs)
PS: Jay added on 10th, may, 2011
# in fact, there may be hyper threading HT Technology, not necessarily 4-core, but 2-core 4-thread; At that time, I didn't understand clearly
? Getconf long_ Bit
32
(indicating that the current CPU is running in 32bit mode, but it does not mean that the CPU does not support 64bit)
# cat / Pro / cpuinfo | grep flags | grep & # 39; lm ' | WC - L
8
(the result is greater than 0, which indicates that 64bit computing is supported. LM means long mode, while LM means 64bit)
let's look at the details of CPU, but most of us don't care about it.
? Dmidecode | grep # 39; Processor Information'
view memory information
# cat / proc / meminfo
# uname - a
linux euis1 2.6.9-55.elsmp # 1 SMP fri APR 20 17:03:35 EDT 2007 i686 i686 i386 GNU / Linux
(view current operating system kernel information)
# cat / etc / issue | grep Linux
Red Hat Enterprise Linux as release 4 (Nahant update 5)
(view current operating system kernel information)
# cat / etc / issue | grep Linux Release information)
view the machine model
? Dmidecode | grep & quot; Proct Name"
View network card information
# dmesg | grep - I eth
6. 大概的介绍一下Linux 的指定CPU运行,包括进程和线程linux下的top命令是可以查看当前的cpu的运行状态,按1可以查看系统有多少个CPU,以及每个CPU的运行状态
可是如何查看线程的CPU呢top
-Hp pid,pid就是你当前程序的进程号,如果是多线程的话,是可以查看进程内所有线程的CPU和内存使用情况
pstree可以查看主次线程,同样的pstree -p pid可以查看进程的线程情况
taskset这个其实才是重点,可以查看以及设置当前进程或线程运行的CPU(设置亲和力)
taskset -pc pid,查看当前进程的cpu,当然有的时候不只是一个,taskset -pc cpu_num pid ,cpu_num就是设置的cpu
这样的话基本的命令和操作其实大家都知道了,接下来就是在代码中完成这些操作,并通过命令去验证代码的成功率
进程制定CPU运行:
[cpp] view plain
#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/sysinfo.h>
#include<unistd.h>
#define __USE_GNU
#include<sched.h>
#include<ctype.h>
#include<string.h>
int main(int argc, char* argv[])
{
//sysconf获取有几个CPU
int num = sysconf(_SC_NPROCESSORS_CONF);
int created_thread = 0;
int myid;
int i;
int j = 0;
//原理其实很简单,就是通过cpu_set_t进行位与操作
cpu_set_t mask;
cpu_set_t get;
if (argc != 2)
{
printf("usage : ./cpu num\n");
exit(1);
}
myid = atoi(argv[1]);
printf("system has %i processor(s). \n", num);
//先进行清空,然后设置掩码
CPU_ZERO(&mask);
CPU_SET(myid, &mask);
//设置进程的亲和力
if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
{
printf("warning: could not set CPU affinity, continuing...\n");
}
while (1)
{
CPU_ZERO(&get);
//获取当前进程的亲和力
if (sched_getaffinity(0, sizeof(get), &get) == -1)
{
printf("warning: cound not get cpu affinity, continuing...\n");
}
for (i = 0; i < num; i++)
{
if (CPU_ISSET(i, &get))
{
printf("this process %d is running processor : %d\n",getpid(), i);
}
}
}
return 0;
}
进程设置CPU运行,其实只能是单线程多线程设定CPU如下:
[cpp] view plain
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sched.h>
void *myfun(void *arg)
{
cpu_set_t mask;
cpu_set_t get;
char buf[256];
int i;
int j;
//同样的先去获取CPU的个数
int num = sysconf(_SC_NPROCESSORS_CONF);
printf("system has %d processor(s)\n", num);
for (i = 0; i < num; i++) {
CPU_ZERO(&mask);
CPU_SET(i, &mask);
//这个其实和设置进程的亲和力基本是一样的
if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
fprintf(stderr, "set thread affinity failed\n");
}
CPU_ZERO(&get);
if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
fprintf(stderr, "get thread affinity failed\n");
}
for (j = 0; j < num; j++)
{
if (CPU_ISSET(j, &get))
{
printf("thread %d is running in processor %d\n", (int)pthread_self(), j);
}
}
j = 0;
while (j++ < 100000000) {
memset(buf, 0, sizeof(buf));
}
}
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t tid;
if (pthread_create(&tid, NULL, (void *)myfun, NULL) != 0)
{
fprintf(stderr, "thread create failed\n");
return -1;
}
pthread_join(tid, NULL);
return 0;
}
可是如何查看线程的CPU呢top
-Hp pid,pid就是你当前程序的进程号,如果是多线程的话,是可以查看进程内所有线程的CPU和内存使用情况
pstree可以查看主次线程,同样的pstree -p pid可以查看进程的线程情况
taskset这个其实才是重点,可以查看以及设置当前进程或线程运行的CPU(设置亲和力)
taskset -pc pid,查看当前进程的cpu,当然有的时候不只是一个,taskset -pc cpu_num pid ,cpu_num就是设置的cpu
这样的话基本的命令和操作其实大家都知道了,接下来就是在代码中完成这些操作,并通过命令去验证代码的成功率
进程制定CPU运行:
[cpp] view plain
#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/sysinfo.h>
#include<unistd.h>
#define __USE_GNU
#include<sched.h>
#include<ctype.h>
#include<string.h>
int main(int argc, char* argv[])
{
//sysconf获取有几个CPU
int num = sysconf(_SC_NPROCESSORS_CONF);
int created_thread = 0;
int myid;
int i;
int j = 0;
//原理其实很简单,就是通过cpu_set_t进行位与操作
cpu_set_t mask;
cpu_set_t get;
if (argc != 2)
{
printf("usage : ./cpu num\n");
exit(1);
}
myid = atoi(argv[1]);
printf("system has %i processor(s). \n", num);
//先进行清空,然后设置掩码
CPU_ZERO(&mask);
CPU_SET(myid, &mask);
//设置进程的亲和力
if (sched_setaffinity(0, sizeof(mask), &mask) == -1)
{
printf("warning: could not set CPU affinity, continuing...\n");
}
while (1)
{
CPU_ZERO(&get);
//获取当前进程的亲和力
if (sched_getaffinity(0, sizeof(get), &get) == -1)
{
printf("warning: cound not get cpu affinity, continuing...\n");
}
for (i = 0; i < num; i++)
{
if (CPU_ISSET(i, &get))
{
printf("this process %d is running processor : %d\n",getpid(), i);
}
}
}
return 0;
}
进程设置CPU运行,其实只能是单线程多线程设定CPU如下:
[cpp] view plain
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sched.h>
void *myfun(void *arg)
{
cpu_set_t mask;
cpu_set_t get;
char buf[256];
int i;
int j;
//同样的先去获取CPU的个数
int num = sysconf(_SC_NPROCESSORS_CONF);
printf("system has %d processor(s)\n", num);
for (i = 0; i < num; i++) {
CPU_ZERO(&mask);
CPU_SET(i, &mask);
//这个其实和设置进程的亲和力基本是一样的
if (pthread_setaffinity_np(pthread_self(), sizeof(mask), &mask) < 0) {
fprintf(stderr, "set thread affinity failed\n");
}
CPU_ZERO(&get);
if (pthread_getaffinity_np(pthread_self(), sizeof(get), &get) < 0) {
fprintf(stderr, "get thread affinity failed\n");
}
for (j = 0; j < num; j++)
{
if (CPU_ISSET(j, &get))
{
printf("thread %d is running in processor %d\n", (int)pthread_self(), j);
}
}
j = 0;
while (j++ < 100000000) {
memset(buf, 0, sizeof(buf));
}
}
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t tid;
if (pthread_create(&tid, NULL, (void *)myfun, NULL) != 0)
{
fprintf(stderr, "thread create failed\n");
return -1;
}
pthread_join(tid, NULL);
return 0;
}
7. Unknown_Error
8. Use the SAR command
SAR
- U
60
5
sample every 60 seconds for 5 consecutive times to observe the usage of CPU
% usr:CPU Percentage of time in user mode< br />% sys:CPU Percentage of time in system mode< br />% wio:CPU Percentage of time waiting for input / output to complete< br />% idle:CPU Percentage of idle time.
SAR
- U
60
5
sample every 60 seconds for 5 consecutive times to observe the usage of CPU
% usr:CPU Percentage of time in user mode< br />% sys:CPU Percentage of time in system mode< br />% wio:CPU Percentage of time waiting for input / output to complete< br />% idle:CPU Percentage of idle time.
9. Let's take a quick up to 100
for I in ` SEQ 1 $(CAT / proc / cpuinfo | grep & quot; physical id" | wc -l)`; Do DD if = / dev / zero of = / dev / null & done
Description:
cat / proc / cpuinfo | grep & quot; physical id" | WC - l can get the number of CPUs, which is expressed as n.
SEQ 1 N is used to generate numbers from 1 to n
for I in ` SEQ 1 N ' It is to execute the command circularly, from 1 to n
DD if = / dev / zero of = / dev / null to execute the DD command, and output to / dev / null. In fact, it only occupies CPU and no IO operation.
e to the continuous execution of n (n is the number of CPUs) DD commands, and the utilization rate is 100%, At this time, the scheler will schele each DD command to be processed on different CPUs.
eventually, the CPU utilization rate will be 100%
the latest Linux technology tutorial book and the introctory self-study book "this is how to learn Linux" will be provided free of charge, so as to make efforts to do more and better for open source technology lovers
for I in ` SEQ 1 $(CAT / proc / cpuinfo | grep & quot; physical id" | wc -l)`; Do DD if = / dev / zero of = / dev / null & done
Description:
cat / proc / cpuinfo | grep & quot; physical id" | WC - l can get the number of CPUs, which is expressed as n.
SEQ 1 N is used to generate numbers from 1 to n
for I in ` SEQ 1 N ' It is to execute the command circularly, from 1 to n
DD if = / dev / zero of = / dev / null to execute the DD command, and output to / dev / null. In fact, it only occupies CPU and no IO operation.
e to the continuous execution of n (n is the number of CPUs) DD commands, and the utilization rate is 100%, At this time, the scheler will schele each DD command to be processed on different CPUs.
eventually, the CPU utilization rate will be 100%
the latest Linux technology tutorial book and the introctory self-study book "this is how to learn Linux" will be provided free of charge, so as to make efforts to do more and better for open source technology lovers
Hot content