在C / C ++代码中有没有使用mbind的例子? [英] Is there any example of using mbind in C/C++ code?

查看:256
本文介绍了在C / C ++代码中有没有使用mbind的例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的帐户中使用 mbind() C ++代码为了重新排列4个NUMA域的虚拟页面,不幸的是我是这个功能的新:

I am trying to use mbind() in my C++ code in order to rearrange virtual pages across 4 NUMA domains, unfortunately I am new to this function:

long mbind(void *addr, unsigned long len, int mode, const unsigned long *nodemask,   
              unsigned long maxnode, unsigned flags);

目前,我有这样的:

mbind(0x0,4611686018424767488,MPOL_BIND,nodemask,maxnode,MPOL_MF_MOVE);

根据规格,我还不清楚要放什么以及如何放置 nodemask maxnode

From the specs it's still unclear to me what to put and how to put for nodemask and maxnode.

推荐答案

nodemask 是指向允许的NUMA节点的位掩码的指针。位掩码是 unsigned long 元素的数组,每个数组元素保存的位数与 unsigned long int 对特定架构允许。除非你的程序运行在一个非常大的NUMA系统上,单个 unsigned long 变量就足够了。

nodemask is a pointer to a bitmask of the allowed NUMA nodes. The bitmask is an array of unsigned long elements with each array element holding as many bits as the size of unsigned long int on the particular architecture allows. Unless your program is running on a really big NUMA system, a single unsigned long variable should suffice.

maxnode 给出 nodemask 中的有效位数。内核在内部舍入大小为 sizeof(unsigned long)的倍数,但仅使用 maxnode 位。

maxnode gives the number of significant bits in nodemask. The kernel rounds internally the size to a multiple of sizeof(unsigned long) but only uses maxnode bits.

有许多例子和库允许你创建和方便地操作位掩码,而不必自己解决位操作。您可以使用 libnuma 。它不允许您设置 MPOL_MF_MOVE 策略,但包括创建和操作nodemask的函数。

There are many examples and libraries around that allow you to create and conveniently manipulate bitmasks without having to fiddle with bit operations yourself. You can utilise libnuma. It doesn't allow you to set the MPOL_MF_MOVE policy but includes functions for the creation and manipulation of nodemasks.

一个可怕且非常不方便的Linux专家:处理CPU相关性掩码的现有宏,即 CPU_ZERO / CPU_SET / CPU_CLR 和关联的数据结构 cpu_set_t 也可用于NUMA nodemask。这是因为(1)都被实现为 unsigned long 的数组和(2)通常比逻辑CPU少NUMA节点,因此 cpu_set_t 应该有足够的位来表示系统上的所有NUMA节点。

A terrible and very unportable Linux pro-tip: The existing macros that deal with the CPU affinity masks, namely CPU_ZERO / CPU_SET / CPU_CLR and the associated data structure cpu_set_t can also be used for NUMA nodemasks. The reason for that is that (1) both are implemented as arrays of unsigned long and (2) there are usually less NUMA nodes than logical CPUs, therefore cpu_set_t should have enough bits to be able to represent all NUMA nodes on the system.

注意: 4611686018424767488 应该可以后缀 LL

这篇关于在C / C ++代码中有没有使用mbind的例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆