Linux???????????CPU
???????????? ???????[ 2015/5/6 13:50:04 ] ??????????????
??????????CPU
????????????????????CPU???????????Linux?????????????????????????CPU??
????#include <pthread.h>
????int pthread_setaffinity_np(pthread_t thread?? size_t cpusetsize?? const cpu_set_t *cpuset);
????int pthread_getaffinity_np(pthread_t thread?? size_t cpusetsize?? cpu_set_t *cpuset);
?????y??????????CPU???????÷???????????
??????????????????CPU?????????????????????CPU?????г????
???????????
#include <stdio.h>
#include <math.h>
#include <pthread.h>
#include <unistd.h>
#include <sched.h>
void WasteTime()
{
int abc = 10000000;
while(abc--)
{
int tmp = 10000*10000;
}
sleep(1);
}
void *thread_func(void *param)
{
cpu_set_t mask;
while(1)
{
CPU_ZERO(&mask);
CPU_SET(1?? &mask);
if (pthread_setaffinity_np(pthread_self()?? sizeof(mask)??
&mask) < 0) {
perror("pthread_setaffinity_np");
}
WasteTime();
CPU_ZERO(&mask);
CPU_SET(2?? &mask);
if (pthread_setaffinity_np(pthread_self()?? sizeof(mask)??
&mask) < 0) {
perror("pthread_setaffinity_np");
}
WasteTime();
}
}
void *thread_func1(void *param)
{
cpu_set_t mask;
while(1)
{
CPU_ZERO(&mask);
CPU_SET(3?? &mask);
if (pthread_setaffinity_np(pthread_self()?? sizeof(mask)??
&mask) < 0) {
perror("pthread_setaffinity_np");
}
WasteTime();
CPU_ZERO(&mask);
CPU_SET(4?? &mask);
if (pthread_setaffinity_np(pthread_self()?? sizeof(mask)??
&mask) < 0) {
perror("pthread_setaffinity_np");
}
WasteTime();
}
}
int main(int argc?? char *argv[])
{
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(0?? &mask);
if (sched_setaffinity(0?? sizeof(mask)?? &mask) < 0) {
perror("sched_setaffinity");
}
pthread_t my_thread;
if (pthread_create(&my_thread?? NULL?? thread_func??
NULL) != 0) {
perror("pthread_create");
}
if (pthread_create(&my_thread?? NULL?? thread_func1??
NULL) != 0) {
perror("pthread_create");
}
while(1) { WasteTime(); }
pthread_exit(NULL);
}
????????
???????????????????????top -p ????id??????f??????j??????????????H??????????????????????cpu0??????????cpu12???л?????????????cpu34????л???
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Linux??????DDR????????????Linux?????????????????豸??????????linux???в???????????м??????????????????????????Linux????Linux??DNS????????????γ???????????Linux?????????????Linux????(???)????????Linux ????????????????????????????????Windows???У?Linux???????Linux????????????????Linux iommu??vfio???????Linux????ε???TCP???????Linux?????????????СLinux?·???????????Linux???Jexus?й?Asp.Net Core??ó???Linux?????????Щ??
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????