def X__getSnmpEntry(mib2, entry): sum = 0 #print("mib2 {0x%x, 0x%x}" % (mib2[0], mib2[1])) for cpu in range(__cpus): mib0 = (percpu.percpu_ptr(long(mib2[0]), cpu)) mib1 = (percpu.percpu_ptr(long(mib2[1]), cpu)) #print("mib0=0x%x, entry=0x%x" % (mib0, entry)) #print("mib1=0x%x, entry=0x%x" % (mib1, entry)) v0 = readULong(mib0 + 8 * entry) v1 = readULong(mib1 + 8 * entry) #print(" entry=%d cpu=%d v0=%d v1=%d" % (entry, cpu, v0, v1)) sum += v0 + v1 #print ("++++sum=%d" %sum) return sum & LONG_MASK
def show_percpu(options): total_count = 0 addr = int(options.percpu, 16) func = None if options.percpu_type == "u8": func = readU8 elif options.percpu_type == "u16": func = readU16 elif options.percpu_type == "u32": func = readU32 elif options.percpu_type == "s32": func = readS32 elif options.percpu_type == "u64": func = readU64 elif options.percpu_type == "s64": func = readS64 elif options.percpu_type == "int": func = readInt for i in range(sys_info.CPUS): percpu_addr = percpu.percpu_ptr(addr, i) print("CPU %d : 0x%x" % (i, percpu_addr)) if options.percpu_type != "": if func: count = func(percpu_addr) print("\t= %d" % (count)) total_count = total_count + count else: print("%s" % (readSU(options.percpu_type, percpu_addr))) if func: print("\tTotal = %d" % (total_count))
def lb_get_stats(priv): # Per-cpu if (symbol_exists("per_cpu__pcpu_lstats")): # 2.6.20 addrs = percpu.get_cpu_var("pcpu_lstats") out = [] for a in addrs: lb_stats = readSU("struct pcpu_lstats", a) stats = Bunch() stats.tx_packets = stats.rx_packets = lb_stats.packets stats.tx_bytes = stats.rx_bytes = lb_stats.bytes out.append(stats) return out elif (symbol_exists("per_cpu__loopback_stats")): addrs = percpu.get_cpu_var("loopback_stats") out = [] for a in addrs: stats = readSU("struct net_device_stats", a) out.append(stats) return out elif (symbol_exists("init_net")): # 2.6.24 out = [] for cpu in range(sys_info.CPUS): a = percpu.percpu_ptr(priv, cpu) lb_stats = readSU("struct pcpu_lstats", a) stats = Bunch() stats.tx_packets = stats.rx_packets = lb_stats.packets stats.tx_bytes = stats.rx_bytes = lb_stats.bytes out.append(stats) return out stats = readSU("struct net_device_stats", priv) return stats
def get_pwq(wq, cpu): if (not (wq.flags & WQ_UNBOUND)): pwq = percpu.percpu_ptr(wq.cpu_pwqs, cpu) else: node = cpu_to_node(cpu) #pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu)); pwq = wq.numa_pwq_tbl[node] return pwq
def __getSnmpEntry(mib2, entry): sum = 0 #print("mib2 {0x%x, 0x%x}" % (mib2[0], mib2[1])) for cpu in range(__cpus): for i in range(__snmp_array_sz): mib = Deref(percpu.percpu_ptr(mib2[i], cpu)) v = mib.mibs[entry] sum += uLong(v) return sum & LONG_MASK
def get_cwqs(wq): if (wq.flags & WQ_UNBOUND): yield wq.cpu_wq.pcpu.gcwq return out = [] for cpu in for_all_cpus(): cwq = percpu.percpu_ptr(wq.cpu_wq.pcpu, cpu) yield cwq.gcwq
def __get_cpu_wqs(_wq): # On older (e.g. 2.6.9) kernels we use # cwq = keventd_wq->cpu_wq + cpu; # On newer ones, # cwq = per_cpu_ptr(keventd_wq->cpu_wq, cpu); cpu_wq = _wq.cpu_wq # If cpu_wq is not an array, this is per_cpu_ptr per_cpu = not isinstance(cpu_wq, list) # CPU-specific out = [] for cpu in range(0, sys_info.CPUS): if (per_cpu): cwq = percpu.percpu_ptr(cpu_wq, cpu) else: cwq = _wq.cpu_wq[cpu] out.append((cpu, cwq)) return out
def show_percpu(options): addr = int(options.percpu, 16) for i in range(sys_info.CPUS): print("CPU %d : 0x%x" % (i, percpu.percpu_ptr(addr, i)))
def cpu_to_node(cpu): ptr = percpu.percpu_ptr(__numa_node, cpu) return readInt(ptr)
def get_gcwq(cpu): if (cpu != WORK_CPU_UNBOUND): return percpu.percpu_ptr(__global_cwq, cpu) else: return readSymbol("unbound_global_cwq")
def printTaskDetails(t): sstate = t.state[5:7] print("---- %6d(%s) %s %s" % (t.pid, sstate, str(t.ts), t.comm)) print(" cpu", t.cpu) parent = t.parent flags = t.flags real_parent = t.Realparent if (parent): print(" -- Parent:", parent.pid, parent.comm) if (real_parent != parent): print(" -- Real Parent:", real_parent.pid, real_parent.comm) children = t.taskChildren() if (children): print(" -- Children: %d" % len(children)) if (verbose): for c in children: print("\t", c.pid, c.comm) # Thread Flags - not ready for all kernel versions yet try: tflags = t.thread_info.flags print(" -- Thread Flags: 0x%x" % tflags) decode_tflags(tflags, 10) except: pass # Stuff from 'struct signal_struct" signal = t.signal # Do we belong to a thread group and are we the leader? if (t.pid != 0 and t.threads): threads = t.threads try: live = ', %d live' % signal.live.counter except: # RHEL3 live = '' print (" -- Threads Info (%d threads%s)" % \ (len(threads)+1, live)) if (t.pid == t.tgid): print("\tI am the leader of a thread group") # Print all threads in verbose mode if (verbose): tids = [t.pid for t in threads] print("\tThreads:", tids) else: print("\tWe belong to a thread group with tgid=%d" % t.tgid) # Credentials # if (t.hasField('cred')): if (t.cred != t.real_cred): job = [('cred', t.cred), ('real_cred', t.real_cred)] else: job = [('Credentials', t.cred)] else: job = [('Credentials', t)] for jh, c in job: print(" --", jh) print("\t uid=%-5d gid=%-5d" % (c.uid, c.gid)) print("\t suid=%-5d sgid=%-5d" % (c.suid, c.sgid)) print("\t euid=%-5d egid=%-5d" % (c.euid, c.egid)) print("\tfsuid=%-5d fsgid=%-5d" % (c.fsuid, c.fsgid)) u = c.user print(" --user_struct", u) if (u.hasField("sigpending")): extra = " sigpending=%d" % u.sigpending.counter else: extra = "" if u.hasField("files"): print("\t processes={} files={}{}".format(atomic_t(u.processes), atomic_t(u.files), extra)) else: print("\t processes={}{}".format(atomic_t(u.processes), extra)) if (c.hasField("group_info")): g = c.group_info ngroups = g.ngroups small_block = g.small_block else: ngroups = t.ngroups small_block = t.groups g = "" print(" --group_info", g) # Print only if we do not have more than NGROUPS_SMALL if (ngroups <= len(small_block)): out = [] for i in range(ngroups): out.append(gid_t(small_block[i])) print(" ", out) # for EXIT_DEAD processes, it does not make sense to continue if (sstate == 'DE'): return # Rlimits print(" -- Rlimits:") # On RHEL4 rlim is in task_struct, on later kernels in signal if t.hasField("rlim"): rlim = t.rlim else: rlim = signal.rlim for i, r in enumerate(rlim): s = __RLIMIT.value2key(i) print("\t%02d (%s) cur=%s max=%s" % (i, s, __rlim2str(r.rlim_cur), __rlim2str(r.rlim_max))) # Accounting info thread_info = readSU("struct thread_info", t.stack) print(" --- thread_info", thread_info) # Don't print accounting info as this nees to be redesigned # to make sense return _e = EnumInfo("enum cgroup_subsys_id") print(t.cgroups.subsys) cs_state = t.cgroups.subsys[_e.cpuacct_subsys_id] ca = container_of(cs_state, "struct cpuacct", "css") print(" --- Accounting Info") while (ca): print(" ", ca, repr(ca.cpuusage)) cpuusage = percpu.percpu_ptr(ca.cpuusage, t.cpu) print(" ", repr(cpuusage), Deref(cpuusage)) ca = ca.parent
def print_disk_stats(gd): ptr = gd.dkstats # gd.dkstats is a per-cpu pointer for cpu in range(sys_info.CPUS): pcpu = percpu_ptr(ptr, cpu) print(" ", cpu, pcpu)