Migrate legacy C++ software to multicore environment

Multicore processors are now widely used in servers, laptops, tablets, eBooks, or even newer smartphones, always ubiquitous.

One of our software modules is also going to move to a multicore platform together with other modules.

Plan to have this migration done in 3 phases:

  1. With least efforts, force the software to run on one of the CPU cores (as a workaround) to ensure stability, without blocking the migration progress of related modules.
  2. Try with multicore mode to find out problems & fix, and optimize the code to take advantage of the multicore environment. Much effort will be spent on code inspection, analysis and optimization. May also look for off-the-shell solutions to expedite the migration.
  3. Formally deploy tested software on multicore platform.

Phase 1

Linux supports locking a process to run on a single CPU core using process affinity.

The change is simple. It’ll be like (error checking is omitted for simplicity):

cpu_set_t mask;CPU_ZERO(&mask);      // clear the "CPU set" represented by the affinity maskCPU_SET(0, &mask);    // add the first available CPU, zero-basedsched_setaffinity(0, sizeof(mask), &mask);    // sets the CPU affinity mask of the calling thread



Reference: http://linux.die.net/man/2/sched_getaffinity


My blog: http://www.cnblogs.com/fanghm
原文链接: https://www.cnblogs.com/fanghm/archive/2012/10/12/2721269.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/65605

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午11:55
下一篇 2023年2月9日 上午11:55

相关推荐