static void s390_elf_corehdr_create(char **elfcorebuf, size_t *elfcorebuf_sz)
{
	Elf64_Phdr *phdr_notes, *phdr_loads;
	int mem_chunk_cnt;
	void *ptr, *hdr;
	u32 alloc_size;
	u64 hdr_off;

	mem_chunk_cnt = get_mem_chunk_cnt();

	alloc_size = 0x1000 + get_cpu_cnt() * 0x300 +
		mem_chunk_cnt * sizeof(Elf64_Phdr);
	hdr = kzalloc_panic(alloc_size);
	/*                 */
	ptr = ehdr_init(hdr, mem_chunk_cnt);
	/*                      */
	phdr_notes = ptr;
	ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr));
	phdr_loads = ptr;
	ptr = PTR_ADD(ptr, sizeof(Elf64_Phdr) * mem_chunk_cnt);
	/*            */
	hdr_off = PTR_DIFF(ptr, hdr);
	ptr = notes_init(phdr_notes, ptr, ((unsigned long) hdr) + hdr_off);
	/*            */
	hdr_off = PTR_DIFF(ptr, hdr);
	loads_init(phdr_loads, ((unsigned long) hdr) + hdr_off);
	*elfcorebuf_sz = hdr_off;
	*elfcorebuf = (void *) relocate((unsigned long) hdr);
	BUG_ON(*elfcorebuf_sz > alloc_size);
}
Example #2
0
File: proc.c Project: tolimit/nmon
	void proc_cpu(struct cpuinfo_brk * cpuinfo_brk)
	{
		if (cpuinfo_brk == NULL)
			return;

		struct data * q = cpuinfo_brk->ext->q;
		struct data * p = cpuinfo_brk->ext->p;
		int i;
		int row;
		int intr_line = 0;
		int ctxt_line = 0;
		int btime_line= 0;
		int proc_line = 0;
		int run_line  = 0;
		int block_line= 0;
		static int proc_cpu_first_time = 1;
		long long user;
		long long nice;
		long long sys;
		long long idle;
		long long iowait;
		long long hardirq;
		long long softirq;
		long long steal;

		get_cpu_cnt(cpuinfo_brk);

		/* Only read data once per interval */
		if( proc_cpu_done == 1)
			return;

		/* If number of CPUs changed, then we need to find the index of intr_line, ... again */
		if( cpuinfo_brk->old_cpus != cpuinfo_brk->cpus)
			intr_line = 0;

		if(proc_cpu_first_time) {
			cpuinfo_brk->ext->stat8 = sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[0][5], "%lld %lld %lld %lld %lld %lld %lld %lld",
					&user,
					&nice,
					&sys,
					&idle,
					&iowait,
					&hardirq,
					&softirq,
					&steal);
			proc_cpu_first_time = 0;
		}

		user = nice = sys = idle = iowait = hardirq = softirq = steal = 0;
		if(cpuinfo_brk->ext->stat8 == 8) {
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[0][5], "%lld %lld %lld %lld %lld %lld %lld %lld",
					&user,
					&nice,
					&sys,
					&idle,
					&iowait,
					&hardirq,
					&softirq,
					&steal);
		} else { /* stat 4 variables here as older Linux proc */
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[0][5], "%lld %lld %lld %lld",
					&user,
					&nice,
					&sys,
					&idle);
		}
		p->cpu_total.user = user + nice;
		p->cpu_total.wait = iowait; /* in the case of 4 variables = 0 */
		p->cpu_total.sys  = sys;
		/* p->cpu_total.sys  = sys + hardirq + softirq + steal;*/
		p->cpu_total.idle = idle;

		p->cpu_total.irq     = hardirq;
		p->cpu_total.softirq = softirq;
		p->cpu_total.steal   = steal;
		p->cpu_total.nice    = nice;

#ifdef DEBUG
		if (debug)
			fprintf(stderr,"XX user=%lld wait=%lld sys=%lld idle=%lld\n",
					p->cpu_total.user,
					p->cpu_total.wait,
					p->cpu_total.sys,
					p->cpu_total.idle);
#endif /*DEBUG*/

		for(i = 0; i < cpuinfo_brk->cpus; i++ ) {
			user = nice = sys = idle = iowait = hardirq = softirq = steal = 0;

			/* allow for large CPU numbers */
			if(i+1 > 1000)
				row = 8;
			else if(i+1 > 100)
				row = 7;
			else if(i+1 > 10)
				row = 6;
			else 
				row = 5;

			if(cpuinfo_brk->ext->stat8 == 8) {
				sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[i+1][row],
						"%lld %lld %lld %lld %lld %lld %lld %lld",
						&user,
						&nice,
						&sys,
						&idle,
						&iowait,
						&hardirq,
						&softirq,
						&steal);
			} else {
				sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[i+1][row], "%lld %lld %lld %lld",
						&user,
						&nice,
						&sys,
						&idle);
			}
			p->cpuN[i].user = user + nice;
			p->cpuN[i].wait = iowait;
			p->cpuN[i].sys  = sys;
			/*p->cpuN[i].sys  = sys + hardirq + softirq + steal;*/
			p->cpuN[i].idle = idle;

			p->cpuN[i].irq     = hardirq;
			p->cpuN[i].softirq = softirq;
			p->cpuN[i].steal   = steal;
			p->cpuN[i].nice    = nice;
		}
		
		if(intr_line == 0) {
			if(cpuinfo_brk->ext->proc[P_STAT].line[i+1][0] == 'p' &&
					cpuinfo_brk->ext->proc[P_STAT].line[i+1][1] == 'a' &&
					cpuinfo_brk->ext->proc[P_STAT].line[i+1][2] == 'g' &&
					cpuinfo_brk->ext->proc[P_STAT].line[i+1][3] == 'e' ) {
				/* 2.4 kernel */
				intr_line = i + 3;
				ctxt_line = i + 5;
				btime_line= i + 6;
				proc_line = i + 7;
				run_line  = i + 8;
				block_line= i + 9;
			}else {
				/* 2.6 kernel */
				intr_line = i + 1;
				ctxt_line = i + 2;
				btime_line= i + 3;
				proc_line = i + 4;
				run_line  = i + 5;
				block_line= i + 6;
			}
		}
		p->cpu_total.intr = -1;
		p->cpu_total.ctxt = -1;
		p->cpu_total.btime = -1;
		p->cpu_total.procs = -1;
		p->cpu_total.running = -1;
		p->cpu_total.blocked = -1;
		if(cpuinfo_brk->ext->proc[P_STAT].lines >= intr_line)
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[intr_line][0], "intr %lld", &p->cpu_total.intr);
		if(cpuinfo_brk->ext->proc[P_STAT].lines >= ctxt_line)
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[ctxt_line][0], "ctxt %lld", &p->cpu_total.ctxt);
		if(cpuinfo_brk->ext->proc[P_STAT].lines >= btime_line)
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[btime_line][0], "btime %lld", &p->cpu_total.btime);
		if(cpuinfo_brk->ext->proc[P_STAT].lines >= proc_line)
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[proc_line][0], "processes %lld", &p->cpu_total.procs);
		if(cpuinfo_brk->ext->proc[P_STAT].lines >= run_line)
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[run_line][0], "procs_running %lld", &p->cpu_total.running);
		if(cpuinfo_brk->ext->proc[P_STAT].lines >= block_line)
			sscanf(&cpuinfo_brk->ext->proc[P_STAT].line[block_line][0], "procs_blocked %lld", &p->cpu_total.blocked);

		/* If we had a change in the number of CPUs, copy current interval data to the previous, so we
		 * get a "0" utilization interval, but better than negative or 100%.
		 * Heads-up - This effects POWER SMT changes too.
		 */
		if( cpuinfo_brk->old_cpus != cpuinfo_brk->cpus )        {
			memcpy((void *) &(q->cpu_total), (void *) &(p->cpu_total), sizeof(struct cpu_stat));
			memcpy((void *) q->cpuN, (void *) p->cpuN, sizeof(struct cpu_stat) * cpuinfo_brk->cpus );
		}

		/* Flag that we processed /proc/stat data; re-set in proc_read() when we re-read /proc/stat */
		proc_cpu_done = 1;
	}