int main(void) { char status[100]; int l = 0; if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, "Cannot open display.\n"); return 1; } for (;;sleep(2)) { l = getcpu(status, sizeof(status)); l += gettemp(status + l, sizeof(status) - l); l += getmem(status + l, sizeof(status) - l); l += getnetwork(status + l, sizeof(status) - l); l += getbattery(status + l, sizeof(status) - l); l += getvol(status + l, sizeof(status) - l); l += getdatetime(status + l, sizeof(status) - l); setstatus(status); } free(status); XCloseDisplay(dpy); return 0; }
// This can go away when RHEL5 support is no longer needed int sched_getcpu(void) { getcpu_p getcpu = (getcpu_p)VSYSCALL_ADDR(__NR_vgetcpu); unsigned cpu = 0; int status = -1; status = getcpu(&cpu, NULL, NULL); return (status == -1) ? status : (int)cpu; }
void c_bo_bo_acquire(struct c_bo_bo *l, int *node) { int cpu, t; if (node == NULL) getcpu(&cpu, node); bo_acquire(l->llocks[*node], *node); if(l->llocks[*node]->state == GLOBAL_RELEASE) { l->llocks[*node]->gstate = bo_acquire(l->glock, *node); l->llocks[*node]->visitors = 0; } else l->llocks[*node]->visitors++; l->llocks[*node]->state = BUSY; }
void main (void) { cpu_type = getcpu(); set_vic_pal(); check_ram_banks(); fixscreen(); while (1) { menu(); tests(); } }
char *get_cpu_name() { switch (getcpu()) { case CPU_6502: return CPU_6502_NAME; case CPU_65C02: return CPU_65C02_NAME; case CPU_65816: return CPU_65816_NAME; default: return CPU_UNKNOWN; } }
void MainWindow::goSetinformation() { QString ee = "\n"; m_bottomWidget->setInformation(ee); getcpu();//获取CPU型号 getcpucores();//获取CPU核数 passwd_sample(); thread_sample(); io_sample(); net_sample(); auditd_sample(); acl_sample(); sel_sample(); }
int main(int argc, char **argv) { uint32_t pmuserenr; MRC_PMU(pmuserenr, PMUSERENR); if (!pmuserenr) { fprintf(stderr, "User access to performance counters disabled, exiting\n"); return 1; } int cpu = getcpu(); printf("Executing CPU: %d\n", cpu); // Set CPU affinity to make sure that the following code is executed on the // CPU printed above. setaff(cpu); enable_pmn(); uint32_t pmcr, pmceid0, pmceid1; MRC_PMU(pmcr, PMCR); MRC_PMU(pmceid0, PMCEID0); MRC_PMU(pmceid1, PMCEID1); printf("PMCR: %"PRIx32"\n", pmcr); printf("PMCEID0: %"PRIx32"\n", pmceid0); printf("PMCEID1: %"PRIx32"\n", pmceid1); set_pmn(0, CPU_CYCLES); set_pmn(1, L1D_CACHE_LD); set_pmn(2, L1D_CACHE_ST); reset_pmn(); reset_ccnt(); // do some fake work for (int i = 0; i < 50; i++) printf("."); uint32_t cycles, cpu_cycles, l1d_cache_ld, l1d_cache_st; MRC_PMU(cycles, PMCCNTR); cpu_cycles = read_pmn(0); l1d_cache_ld = read_pmn(1); l1d_cache_st = read_pmn(2); printf("\nCPU cycles: %"PRIu32"\n", cpu_cycles); printf("Cycle Count: %"PRIu32"\n", cycles); printf("Level 1 data cache access, read: %"PRIu32"\n", l1d_cache_ld); printf("Level 1 data cache access, write: %"PRIu32"\n", l1d_cache_st); return 0; }
static void ctlstat_standard(struct ctlstat_context *ctx) { long double etime; uint64_t delta_jiffies, delta_idle; uint32_t port; long double cpu_percentage; int i; int j; cpu_percentage = 0; if (F_CPU(ctx) && (getcpu(&ctx->cur_cpu) != 0)) errx(1, "error returned from getcpu()"); etime = ctx->cur_time.tv_sec - ctx->prev_time.tv_sec + (ctx->prev_time.tv_nsec - ctx->cur_time.tv_nsec) * 1e-9; if (F_CPU(ctx)) { ctx->prev_total_jiffies = ctx->cur_total_jiffies; ctx->cur_total_jiffies = ctx->cur_cpu.user + ctx->cur_cpu.nice + ctx->cur_cpu.system + ctx->cur_cpu.intr + ctx->cur_cpu.idle; delta_jiffies = ctx->cur_total_jiffies; if (F_FIRST(ctx) == 0) delta_jiffies -= ctx->prev_total_jiffies; ctx->prev_idle = ctx->cur_idle; ctx->cur_idle = ctx->cur_cpu.idle; delta_idle = ctx->cur_idle - ctx->prev_idle; cpu_percentage = delta_jiffies - delta_idle; cpu_percentage /= delta_jiffies; cpu_percentage *= 100; } if (F_HDR(ctx)) { ctx->header_interval--; if (ctx->header_interval <= 0) { int hdr_devs; hdr_devs = 0; if (F_TOTALS(ctx)) { fprintf(stdout, "%s System Read %s" "System Write %sSystem Total%s\n", (F_LUNVAL(ctx) != 0) ? " " : "", (F_LUNVAL(ctx) != 0) ? " " : "", (F_LUNVAL(ctx) != 0) ? " " : "", (F_CPU(ctx) == 0) ? " CPU" : ""); hdr_devs = 3; } else { if (F_CPU(ctx)) fprintf(stdout, " CPU "); for (i = 0; i < min(CTL_STAT_LUN_BITS, ctx->num_luns); i++) { int lun; /* * Obviously this won't work with * LUN numbers greater than a signed * integer. */ lun = (int)ctx->cur_lun_stats[i ].lun_number; if (bit_test(ctx->lun_mask, lun) == 0) continue; fprintf(stdout, "%15.6s%d ", "lun", lun); hdr_devs++; } fprintf(stdout, "\n"); } for (i = 0; i < hdr_devs; i++) fprintf(stdout, "%s %sKB/t %s MB/s ", ((F_CPU(ctx) != 0) && (i == 0) && (F_TOTALS(ctx) == 0)) ? " " : "", (F_LUNVAL(ctx) != 0) ? " ms " : "", (F_DMA(ctx) == 0) ? "tps" : "dps"); fprintf(stdout, "\n"); ctx->header_interval = 20; } } if (F_TOTALS(ctx) != 0) { long double mbsec[3]; long double kb_per_transfer[3]; long double transfers_per_sec[3]; long double ms_per_transfer[3]; long double ms_per_dma[3]; long double dmas_per_sec[3]; for (i = 0; i < 3; i++) ctx->prev_total_stats[i] = ctx->cur_total_stats[i]; memset(&ctx->cur_total_stats, 0, sizeof(ctx->cur_total_stats)); /* Use macros to make the next loop more readable. */ #define ADD_STATS_BYTES(st, p, i, j) \ ctx->cur_total_stats[st].ports[p].bytes[j] += \ ctx->cur_lun_stats[i].ports[p].bytes[j] #define ADD_STATS_OPERATIONS(st, p, i, j) \ ctx->cur_total_stats[st].ports[p].operations[j] += \ ctx->cur_lun_stats[i].ports[p].operations[j] #define ADD_STATS_NUM_DMAS(st, p, i, j) \ ctx->cur_total_stats[st].ports[p].num_dmas[j] += \ ctx->cur_lun_stats[i].ports[p].num_dmas[j] #define ADD_STATS_TIME(st, p, i, j) \ bintime_add(&ctx->cur_total_stats[st].ports[p].time[j], \ &ctx->cur_lun_stats[i].ports[p].time[j]) #define ADD_STATS_DMA_TIME(st, p, i, j) \ bintime_add(&ctx->cur_total_stats[st].ports[p].dma_time[j], \ &ctx->cur_lun_stats[i].ports[p].dma_time[j]) for (i = 0; i < ctx->num_luns; i++) { for (port = 0; port < CTL_MAX_PORTS; port++) { for (j = 0; j < CTL_STATS_NUM_TYPES; j++) { ADD_STATS_BYTES(2, port, i, j); ADD_STATS_OPERATIONS(2, port, i, j); ADD_STATS_NUM_DMAS(2, port, i, j); ADD_STATS_TIME(2, port, i, j); ADD_STATS_DMA_TIME(2, port, i, j); } ADD_STATS_BYTES(0, port, i, CTL_STATS_READ); ADD_STATS_OPERATIONS(0, port, i, CTL_STATS_READ); ADD_STATS_NUM_DMAS(0, port, i, CTL_STATS_READ); ADD_STATS_TIME(0, port, i, CTL_STATS_READ); ADD_STATS_DMA_TIME(0, port, i, CTL_STATS_READ); ADD_STATS_BYTES(1, port, i, CTL_STATS_WRITE); ADD_STATS_OPERATIONS(1, port, i, CTL_STATS_WRITE); ADD_STATS_NUM_DMAS(1, port, i, CTL_STATS_WRITE); ADD_STATS_TIME(1, port, i, CTL_STATS_WRITE); ADD_STATS_DMA_TIME(1, port, i, CTL_STATS_WRITE); } } for (i = 0; i < 3; i++) { compute_stats(&ctx->cur_total_stats[i], F_FIRST(ctx) ? NULL : &ctx->prev_total_stats[i], etime, &mbsec[i], &kb_per_transfer[i], &transfers_per_sec[i], &ms_per_transfer[i], &ms_per_dma[i], &dmas_per_sec[i]); if (F_DMA(ctx) != 0) fprintf(stdout, " %2.2Lf", ms_per_dma[i]); else if (F_LUNVAL(ctx) != 0) fprintf(stdout, " %2.2Lf", ms_per_transfer[i]); fprintf(stdout, " %5.2Lf %3.0Lf %5.2Lf ", kb_per_transfer[i], (F_DMA(ctx) == 0) ? transfers_per_sec[i] : dmas_per_sec[i], mbsec[i]); } if (F_CPU(ctx)) fprintf(stdout, " %5.1Lf%%", cpu_percentage); } else { if (F_CPU(ctx)) fprintf(stdout, "%5.1Lf%% ", cpu_percentage); for (i = 0; i < min(CTL_STAT_LUN_BITS, ctx->num_luns); i++) { long double mbsec, kb_per_transfer; long double transfers_per_sec; long double ms_per_transfer; long double ms_per_dma; long double dmas_per_sec; if (bit_test(ctx->lun_mask, (int)ctx->cur_lun_stats[i].lun_number) == 0) continue; compute_stats(&ctx->cur_lun_stats[i], F_FIRST(ctx) ? NULL : &ctx->prev_lun_stats[i], etime, &mbsec, &kb_per_transfer, &transfers_per_sec, &ms_per_transfer, &ms_per_dma, &dmas_per_sec); if (F_DMA(ctx)) fprintf(stdout, " %2.2Lf", ms_per_dma); else if (F_LUNVAL(ctx) != 0) fprintf(stdout, " %2.2Lf", ms_per_transfer); fprintf(stdout, " %5.2Lf %3.0Lf %5.2Lf ", kb_per_transfer, (F_DMA(ctx) == 0) ? transfers_per_sec : dmas_per_sec, mbsec); } } }
void rw_acquire(struct rw *l, mode m, int *node) { int cpu, patience = 0; bool braised; getcpu(&cpu, node); if(m == R) { /* readers */ switch (l->pref) { case NEUTRAL: c_bo_bo_acquire(l->writers, node); __sync_fetch_and_add(&l->indicators[*node].arrive, 1); c_bo_bo_release(l->writers, *node); break; case READER: while(l->rbarrier); /* If we need less granularity, we can change later*/ __sync_fetch_and_add(&l->indicators[*node].arrive, 1); while(c_bo_bo_islocked(l->writers)); break; case READER_OPT: while(l->rbarrier); /* If we need less granularity, we can change later*/ __sync_fetch_and_add(&l->indicators[*node].arrive, 1); while(l->wactive); break; case WRITER: braised = false; while (true) { __sync_fetch_and_add(&l->indicators[*node].arrive, 1); if(c_bo_bo_islocked(l->writers)) { __sync_fetch_and_add(&l->indicators[*node].depart, 1); while (c_bo_bo_islocked(l->writers)) { patience++; if (patience > PATIENCE && !braised) { __sync_fetch_and_add(&l->wbarrier, 1); braised = true; } } continue; } if(braised) __sync_fetch_and_sub(&l->wbarrier, 1); break; } } } else { /* writers */ switch (l->pref) { case NEUTRAL: c_bo_bo_acquire(l->writers, node); readindr_waitempty(l->indicators); break; case READER: braised = false; while (true) { c_bo_bo_acquire(l->writers, node); if(!readindr_isempty(l->indicators)) { c_bo_bo_release(l->writers, *node); while (!readindr_isempty(l->indicators)) { patience++; if (patience > PATIENCE && !braised) { /* erect barrier */ __sync_fetch_and_add(&l->rbarrier, 1); braised = true; } } continue; } if(braised) __sync_fetch_and_sub(&l->rbarrier, 1); break; } break; case READER_OPT: braised = false; c_bo_bo_acquire(l->writers, node); while (true) { while(!readindr_isempty(l->indicators)) { patience++; if (patience > PATIENCE && !braised) { __sync_fetch_and_add(&l->rbarrier, 1); braised = true; } } l->wactive = true; if(!readindr_isempty(l->indicators)) { l->wactive = false; continue; } if(braised) __sync_fetch_and_sub(&l->rbarrier, 1); break; } break; case WRITER: while(l->wbarrier); c_bo_bo_acquire(l->writers, node); readindr_waitempty(l->indicators); } } }