查找线程访问的页面 [英] find the pages accessed by thread

查看:52
本文介绍了查找线程访问的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些基于线程访问的数据的调度选项.有什么方法可以找到特定线程访问的缓存页面. 如果我有来自两个不同进程的两个线程,是否有可能找到两个线程访问的公共数据/页面

I am looking for some scheduling options based on data accessed by threads. Is there any way to find the pages of cache accessed by a specific thread. If i have two threads from two different processes, is it possible to find the common data/pages accessed by both the threads

推荐答案

来自同一进程的两个线程可能共享整个进程的内存空间.如果该程序没有将访问内存的特定区域限制为线程,那么可能很难准确地知道应该将哪个线程分配给哪个cpu.

Two threads from the same process are potentially sharing the whole process memory space. If the programme does not restrict access to certain regions of memory to the threads, it might be difficult to know exactly which thread should be assigned to which cpu.

对于更多线程,问题变得更加棘手,因为一个线程可能与几个不同的线程共享不同的数据,并建立关系网络.如果两个线程之间的关系要求它们与给定的cpu内核具有亲和性,则通过传递性,其关系网络的所有线程也应绑定到该同一个内核. 关系的数量或某种形式的聚类分析(双向连通性)可能会有所帮助.

For more threads, the problem becomes more difficult, as a thread may share different data with several different threads, and create a network of relationship. If a relation between two threads mandates their affinity to a given cpu core, by transitivity all the threads of their relationship network should be bound to that very same core as well. Perhaps the number of relations, or some form of clustering analysis (biconnectivity) would help.

关于您的特定问题,如果两个线程正在共享数据,但是来自不同的进程,则这些进程必须通过使用shm_open(创建共享内存段)和mmap(映射)来自愿共享这些页面.该段在过程存储器中).否则,将无法在进程之间共享数据页,除非隐式地(再次)与操作系统用于分叉进程的写入时复制机制有关,在这种情况下,每个页面保持共享状态,直到一个进程对其进行写操作为止.

Regarding your specific question, if two threads are sharing data, but are from different processes, then these processes are necessarily sharing these pages voluntarily by using shm_open (to create a shared memory segment) and mmap (to map that segment in the process memory). It is not possible to share data pages between processes otherwise, excepted implicitely (again) with the copy on write mechanism used by the OS for forked processes, in which case each page remains shared until one process makes a write to it.

页面的显式共享(通过shm_open)可用于以编程方式为两个线程定义相同的CPU亲和力-可能是通过两个程序中的约定将相关线程与第一个内核相关联,或者是通过小的握手协议通过共享内存对象在某个点建立(例如,可以通过访问它的第一个线程将内存段的第一个字节设置为所选的CPU编号+ 1,0表示尚无亲和力.)

The explicit sharing of pages (by shm_open) may be used to programmatically define the same CPU affinity for both threads - perhaps by convention in both programs to associate the relevant threads with the first core, or through a small handshaking protocol established at some point through the shared memory object (for instance the first byte of the memory segment could be set to the chosen cpu number + 1 by the first thread to access it, 0 meaning no affinity yet).

不幸的是,posix线程API没有提供一种设置线程的cpu亲和力的方法.您可以使用linux平台pthread_attr_setaffinity_np上提供的非便携式扩展程序以及cpuset系列功能来配置线程关联.

Unfortunately, the posix thread API doesn't provide a way to set cpu affinity for threads. You may use the non portable extension provided on the linux platform pthread_attr_setaffinity_np, with the cpuset family of functions to configure a thread affinity.

参考:

  • cpuset
  • pthread_attr_setaffinity_np

这篇关于查找线程访问的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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