欢迎来到冰豆网! | 帮助中心 分享价值,成长自我!
冰豆网
全部分类
  • IT计算机>
  • 经管营销>
  • 医药卫生>
  • 自然科学>
  • 农林牧渔>
  • 人文社科>
  • 工程科技>
  • PPT模板>
  • 求职职场>
  • 解决方案>
  • 总结汇报>
  • 党团工作>
  • ImageVerifierCode 换一换
    首页 冰豆网 > 资源分类 > DOCX文档下载
    分享到微信 分享到微博 分享到QQ空间

    多核处理器LINUX的进程绑定处理器核运行Word文件下载.docx

    • 资源ID:17780819       资源大小:980.72KB        全文页数:15页
    • 资源格式: DOCX        下载积分:12金币
    快捷下载 游客一键下载
    账号登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录
    二维码
    微信扫一扫登录
    下载资源需要12金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP,免费下载
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    多核处理器LINUX的进程绑定处理器核运行Word文件下载.docx

    1、void CPU_CLR (int cpu, cpu_set_t *set)这个宏将 cpu 从 CPU 集 set 中删除。int CPU_ISSET (int cpu, const cpu_set_t *set)如果 cpu 是 CPU 集 set 的一员,这个宏就返回一个非零值(true),否则就返回零(false)。Example:我是在一个虚拟机上运行的程序,机器CPU是双核的,我设置虚拟机模拟四核。在linux上执行top指令看结果,点击“1”查看每个CPU核的运行情况。/* Short test program to test sched_setaffinity* (which

    2、sets the affinity of processes to processors).* Compile: gcc sched_setaffinity_test.c * -o sched_setaffinity_test.o -lm* Usage: ./sched_setaffinity_test.o* Open a top-window at the same time and see all the work* being done on CPU 0 first and after a short wait on CPU 1,2,3.* Repeat with different n

    3、umbers to make sure, it is not a* coincidence.*/#include math.hsched.hdouble waste_time(long n) double res = 0; long i = 0; while(i n * 200000) i+; res += sqrt(i); return res;int main(int argc, char *argv) unsigned long mask = 1; /* 二进制1,processor 0 */ /* bind process to processor 0 */ if (sched_set

    4、affinity(0, sizeof(mask), &mask) 0) perror(sched_setaffinity); /* waste some time so the work is visible with */ printf (result: %fn, waste_time (2000); mask = 2; /*二进制10, process switches to processor 1 now */ /* waste some more time to see the processor switch */ mask = 4; /* 二进制100,processor 2 */

    5、 /* bind process to processor 2 */ mask = 8; /* 二进制1000,process switches to processor 3 now */ 2、运行结果图2-1:图中显示编译及执行一个使用“CPU亲和力”的程序。图2-2 可以看见CPU0已在执行程序(CPU达到100.0%?有必要吗),第一段程序的结果还未出来。图2-3 可以看见CPU1已在执行程序,第一段程序的结果已经显示(图片中显示了上一次执行的结果,因为截图比较慢,执行了3次-),CPU1执行的结果还未显示出来。图2-4:可以看见CPU2已在执行程序,第二段程序(CPU1执行)的结果已经

    6、显示,CPU2执行的程序结果还未出来。图2-5::CPU3再执行程序。图2-6:结果已经显示,CPU恢复到执行之前的状态二、多进程(在两个核上各自运行一个进程)1、代码如下/* Short test program to test parallel_setaffinity_test.c gcc parallel_setaffinity_test.c * -o parallel_setaffinity_test.o -lm ./parallel_setaffinity_test.o* being done on CPU 0 first and after a short wait on CPU

    7、1. #includesys/types.hsys/sysinfo.hunistd.hstring.h #include double waste_time(long n) double res = 0; long i = 0; while(i i+; res += sqrt(i); return res; int main() char buf100; pid_t cld_pid; int fd; int status; unsigned long mask = 0; strcpy(buf,This is parent process write!n if(cld_pid=fork()=0)

    8、 strcpy(buf,This is child process write! printf(This is child process!My PID(child) is %dn,getpid();,getppid(); mask = 1; /* bind process to processor 0 */ if (sched_setaffinity(0, sizeof(mask), & perror( /* waste some time so the work is visible with printf ( %f.n write(fd,buf,strlen(buf); close(fd

    9、); exit(0); elseThis is parent process!My PID(parent) is %d.nMy child PID is %d.n,cld_pid); mask = 2; /* waste some more time to see the processor switch */ wait(&status); return 0;图3-1:图中显示编译及执行一个使用“CPU亲和力”的多进程程序,双核(虚拟四核太慢)。图3-2:,父子进程并发执行,父进程在CPU1上运行,子进程运行在CPU0,可以看出两个处理器目前都在运行程序。图3-3:结果已经显示,CPU0和CP

    10、U1都恢复到执行之前的状态附录1、Processor affinityis a modification of the native central queuescheduling algorithmin asymmetric multiprocessingoperating system. Each task (be it process or thread) in the queue has a tag indicating its preferred / kinprocessor. At allocation time, each task is allocated to its kin

    11、 processor in preference to others.Processor affinity takes advantage of the fact that some remnants of a process may remain in one processors state (in particular, in itscache) from the last time the process ran. Scheduling it to run on the same processor the next time could result in the processs

    12、running more efficiently by reducing performance-degrading situations such as cache misses. A practical example might be running multiple instances of an application which does not use multiple threads, such as some graphics-rendering software. Overall system efficiency increases.Scheduling algorith

    13、m implementations vary in adherence to processor affinity. Under certain circumstances some implementations will allow a task to change to another processor if this is deemed to be most efficient. This may be the case if two processor-intensive tasks (A & B) have affinity to one processor while anot

    14、her processor lies unused. Many algorithms would shift task B to the second processor in order to maximize processor use. Task B would then acquire affinity with the second processor while task A would continue to have affinity with the original processor.Processor affinity can effectively reduce ca

    15、che problems but it does not curb the persistentload-balancingproblem.1Further, processor affinity becomes more complicated in systems with non-uniform architectures. For example, a system with two dual-corehyper-threadedCPUs presents a challenge to a scheduling algorithm. There is complete affinity

    16、 between two virtual CPUs implemented on the same core via hyper-threading, partial affinity between two cores on the same physical chip (as the cores share some, but not all, cache), and no affinity between separate physical chips.As other resources are also shared, processor affinity alone cannot

    17、be used as the basis for CPU dispatching. If a process has recently run on one virtual hyper-threaded CPU in a given core, and that virtual CPU is currently busy but its partner is not, cache affinity would suggest that the process should be dispatched to the idle partner. However, the two virtual C

    18、PUs compete for essentially all computing, cache, and memory resources. It would typically be more efficient in this case to dispatch the process to a different core or CPU if one is available. This would likely incur a penalty when process repopulates the cache, but overall performance would likely

    19、 be higher as the process would not have to compete for resources within the CPU.OnLinuxthe CPU affinity of a process might be altered with the taskset(1) program.2SGIsystems,dplacebinds a process to a set of CPUs.3NetBSD5.0,FreeBSD7.2 and later versions can use pthread_setaffinity_np and pthread_ge

    20、taffinity_np.4InNetBSD, the psrset utility5to set a threads affinity to a certain CPU set. InFreeBSD, cpuset6utility is used to create CPU sets and to assign processes to these sets. OnWindows NT, thread and process CPU affinities can be set separately by using SetThreadAffinityMask7and SetProcessAf

    21、finityMask8API calls or via the Task Manager interface (for process affinity only).Mac OS Xexposes anaffinity APIthat provides hints to the kernel how to schedule threads according to affinity sets.2、sched_setaffinity, sched_getaffinity - set and get a processs CPU affinity maskSYNOPSISDESCRIPTIONsc

    22、hed_setaffinity sets the CPU affinity mask of the process denoted by pid. If pid is zero, then the current process is used.The affinity mask is represented by the bitmask stored in mask. The least significant bit corresponds to the first logical processor number on the system, while the most signifi

    23、cant bit corresponds to the last logical processor number on the system. A set bit corresponds to a legally schedulable CPU while an unset bit corresponds to an illegally schedulable CPU. In other words, a process is bound to and will only run on processors whose corresponding bit is set. Usually, a

    24、ll bits in the mask are set.The argument len is the length of the data pointed to by mask. Normally this is the size of a word on the system. For compatibility with future versions of the Linux kernel, since this size can change, the bitmask supplied must be at least as large as the affinity mask stored in the kernel.The function


    注意事项

    本文(多核处理器LINUX的进程绑定处理器核运行Word文件下载.docx)为本站会员主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

    copyright@ 2008-2022 冰点文档网站版权所有

    经营许可证编号:鄂ICP备2022015515号-1

    收起
    展开