首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LINUX: ITIMER_PROF的分辨率/粒度是什么?

问LINUX: ITIMER_PROF的分辨率/粒度是什么?
EN

Stack Overflow用户
提问于 2014-04-03 20:52:44
回答 1查看 897关注 0票数 1

问题:

LINUX配置文件计时器的分辨率是多少?显然,这是具体的系统,所以我将提供更多的细节如下。

背景:

我正在尝试使用Google GPerfTools套件,我发现无论我多么努力,我都不能获得超过200个样本/秒的CPU时间(不是挂钟时间,甚至更低),尽管GPerfTools中允许的最大值是4000/秒。

Please see this (unloved) question: /questions/22799490

在查看GPerfTools代码时,我还发现它使用的是一个ITIMER_PROF (这并不奇怪),并且使用了具有正确的timestruct值的setitimer(2)系统调用(duh!):

代码语言:javascript
复制
void ProfileHandler::StartTimer() {
  if (!allowed_) {
    return;
  }
  struct itimerval timer;
  timer.it_interval.tv_sec = 0;
  timer.it_interval.tv_usec = 1000000 / frequency_;
  timer.it_value = timer.it_interval;
  setitimer(timer_type_, &timer, 0);
}

因此,对采样率的限制要么在系统ITIMER_PROF限制中,要么是GPerfTools如何与我正在分析的程序交互的副产品(也许计时器在I/O上被阻塞时就停止了?)当那个不算为样本的happens...maybe?:)

系统细节:

我在运行Ubuntu的标准x86_64盒上运行。这是我的结果:Linux <hostname> 3.2.0-58-generic #88-Ubuntu SMP Tue Dec 3 17:37:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

程序和GPerfTools库以32位模式编译.事实上,GPerfTools构建中的GPerfTools步骤是在32位chroot'd监狱setarch'd to i386中完成的。

EN

回答 1

Stack Overflow用户

发布于 2014-04-05 02:14:41

在不同的Ubuntu LINUX盒(包括x86虚拟机)上重复测试都可以确认每秒250次,或者在实际使用x86时间隔4ms。在这个时代,这是否真的是正确的呢?测试程序包括在下面

举例结果:

代码语言:javascript
复制
./itimer 200 3
freq = 200
timeout = 3
When over, you should see 599 firings
PERF timer fired 599 times
VIRTUAL timer fired 599 times

./itimer 500 3
freq = 500
timeout = 3
When over, you should see 1499 firings
PERF timer fired 749 times
VIRTUAL timer fired 749 times

测试程序

代码语言:javascript
复制
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>

struct itimerval mrVal;
struct itimerval timeout;

int ncalls = 0;
int nvcalls = 0;
void killer(int signum)
{
    // Off by a few because we don't stop the timers,
    // but good enough for testing purposes
    printf("PERF timer fired %d times\n", ncalls);
    printf("VIRTUAL timer fired %d times\n", nvcalls);
    exit(0);
}

void interval_handler(int signum)
{
    ncalls += 1;
}

void virtual_handler(int signum)
{
    nvcalls += 1;
}

static double keeper = 12.345;

int main(int argc, char **argv)
{
    if (argc < 3) {
        printf("Usage: itimer freq seconds-to-run\n");
        exit(1);
    }
    int freq = atoi(argv[1]);
    int sleepsex = atoi(argv[2]);
    printf("freq = %d\n", freq);
    printf("timeout = %d\n", sleepsex);
    printf("When over, you should see %d firings\n",
                    (freq * sleepsex) - 1);

    timeout.it_interval.tv_sec = sleepsex;
    timeout.it_interval.tv_usec = 0;
    timeout.it_value = timeout.it_interval;

    mrVal.it_interval.tv_sec = 0;
    mrVal.it_interval.tv_usec = 1000000 / freq;
    mrVal.it_value = mrVal.it_interval;
    if(signal(SIGPROF, interval_handler) == SIG_ERR) {
        printf("HOSER!\n");
    }
    if(signal(SIGVTALRM, virtual_handler) == SIG_ERR) {
        printf("HOSER!\n");
    }
    if(signal(SIGALRM, killer) == SIG_ERR) {
        printf("HOSER!\n");
    }
    if(signal(SIGINT, killer) == SIG_ERR) {
        printf("HOSER!\n");
    }
    setitimer(ITIMER_PROF, &mrVal, 0);
    setitimer(ITIMER_VIRTUAL, &mrVal, 0);
#if 1
    // Use CPU. Otherwise, the PERF timer doesn't go off
    // Trivial floating point stuff that counts good enough
    // as work
    setitimer(ITIMER_REAL, &timeout, 0);
    while(1) {
        double d = keeper;
        d/=1.3773;
        d*=1.3777;
        keeper = d;
    }
#else
    sleep(sleepsex);
    killer(0);
#endif
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22848764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档