gcc compiler option and kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yestoday , I use objdump to get disassembly code of kernel/sched.c, but I find it too difficult to read the code .
I compiled kernel without using the frame pointer bp. It seems that functions arguments can be passed by stack , or by register, or by both of them. For function's local variables there has the same problem. I even cannot figure out where the arguments are stored.Can someone introduce some general principles used by gcc compiling the kernel? Such as the order which registers(ESI,EDI,EAX etc.) are allocated.
Using frame pointer may be a good choice?
Thanks !
Bao Zhao


an example listed below.
where are this_cpu, this_rq, sd,group,busiest , imbalance, nr_moved stored?


static int load_balance_newidle(int this_cpu, runqueue_t *this_rq,
				struct sched_domain *sd)
{
	struct sched_group *group;
	runqueue_t *busiest = NULL;
	unsigned long imbalance;
	int nr_moved = 0;

	group = find_busiest_group(sd, this_cpu, &imbalance, NEWLY_IDLE);
	if (!group)
		goto out;

	busiest = find_busiest_queue(group);
	if (!busiest || busiest == this_rq)
		goto out;

	/* Attempt to move tasks */
	double_lock_balance(this_rq, busiest);

	nr_moved = move_tasks(this_rq, this_cpu, busiest,
					imbalance, sd, NEWLY_IDLE);

	spin_unlock(&busiest->lock);

out:
	return nr_moved;
}

00001c8f <load_balance_newidle>:
   1c8f:	55                   	push   %ebp
   1c90:	89 e5                	mov    %esp,%ebp
   1c92:	83 ec 24             	sub    $0x24,%esp
   1c95:	89 7d fc             	mov    %edi,0xfffffffc(%ebp)
   1c98:	89 75 f8             	mov    %esi,0xfffffff8(%ebp)
   1c9b:	89 45 ec             	mov    %eax,0xffffffec(%ebp)
   1c9e:	89 cf                	mov    %ecx,%edi
   1ca0:	89 d6                	mov    %edx,%esi
   1ca2:	89 5d f4             	mov    %ebx,0xfffffff4(%ebp)
   1ca5:	89 c2                	mov    %eax,%edx
   1ca7:	8d 4d f0             	lea    0xfffffff0(%ebp),%ecx
   1caa:	c7 45 e8 00 00 00 00 	movl   $0x0,0xffffffe8(%ebp)
   1cb1:	89 f8                	mov    %edi,%eax
   1cb3:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
   1cba:	e8 22 fa ff ff       	call   16e1 <find_busiest_group>
   1cbf:	85 c0                	test   %eax,%eax
   1cc1:	74 4e                	je     1d11 <load_balance_newidle+0x82>
   1cc3:	e8 3d fd ff ff       	call   1a05 <find_busiest_queue>
   1cc8:	85 c0                	test   %eax,%eax
   1cca:	89 c3                	mov    %eax,%ebx
   1ccc:	74 43                	je     1d11 <load_balance_newidle+0x82>
   1cce:	39 f0                	cmp    %esi,%eax
   1cd0:	74 3f                	je     1d11 <load_balance_newidle+0x82>
   1cd2:	89 c2                	mov    %eax,%edx
   1cd4:	89 f0                	mov    %esi,%eax
   1cd6:	e8 04 f7 ff ff       	call   13df <double_lock_balance>
   1cdb:	8b 55 ec             	mov    0xffffffec(%ebp),%edx
   1cde:	89 d9                	mov    %ebx,%ecx
   1ce0:	8b 45 f0             	mov    0xfffffff0(%ebp),%eax
   1ce3:	c7 44 24 08 02 00 00 	movl   $0x2,0x8(%esp)
   1cea:	00
   1ceb:	89 7c 24 04          	mov    %edi,0x4(%esp)
   1cef:	89 04 24             	mov    %eax,(%esp)
   1cf2:	89 f0                	mov    %esi,%eax
   1cf4:	e8 a7 f7 ff ff       	call   14a0 <move_tasks>
   1cf9:	89 45 e8             	mov    %eax,0xffffffe8(%ebp)
   1cfc:	c6 03 01             	movb   $0x1,(%ebx)
   1cff:	b8 00 e0 ff ff       	mov    $0xffffe000,%eax
   1d04:	21 e0                	and    %esp,%eax
   1d06:	83 68 14 01          	subl   $0x1,0x14(%eax)
   1d0a:	8b 40 08             	mov    0x8(%eax),%eax
   1d0d:	a8 08                	test   $0x8,%al
   1d0f:	75 10                	jne    1d21 <load_balance_newidle+0x92>
   1d11:	8b 45 e8             	mov    0xffffffe8(%ebp),%eax
   1d14:	8b 5d f4             	mov    0xfffffff4(%ebp),%ebx
   1d17:	8b 75 f8             	mov    0xfffffff8(%ebp),%esi
   1d1a:	8b 7d fc             	mov    0xfffffffc(%ebp),%edi
   1d1d:	89 ec                	mov    %ebp,%esp
   1d1f:	5d                   	pop    %ebp
   1d20:	c3                   	ret
   1d21:	e8 fc ff ff ff       	call   1d22 <load_balance_newidle+0x93>
   1d26:	eb e9                	jmp    1d11 <load_balance_newidle+0x82>


static struct sched_group * find_busiest_group(struct sched_domain *sd, int this_cpu, unsigned long *imbalance, enum idle_type idle) { struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; unsigned long max_load, avg_load, total_load, this_load, total_pwr;

	max_load = this_load = total_load = total_pwr = 0;

	do {
		cpumask_t tmp;
		unsigned long load;
		int local_group;
		int i, nr_cpus = 0;

		local_group = cpu_isset(this_cpu, group->cpumask);

		/* Tally up the load of all CPUs in the group */
		avg_load = 0;
		cpus_and(tmp, group->cpumask, cpu_online_map);
		if (unlikely(cpus_empty(tmp)))
			goto nextgroup;

		for_each_cpu_mask(i, tmp) {
			/* Bias balancing toward cpus of our domain */
			if (local_group)
				load = target_load(i);
			else
				load = source_load(i);

			nr_cpus++;
			avg_load += load;
		}

		if (!nr_cpus)
			goto nextgroup;

		total_load += avg_load;
		total_pwr += group->cpu_power;

		/* Adjust by relative CPU power of the group */
		avg_load = (avg_load * SCHED_LOAD_SCALE) / group->cpu_power;

		if (local_group) {
			this_load = avg_load;
			this = group;
			goto nextgroup;
		} else if (avg_load > max_load) {
			max_load = avg_load;
			busiest = group;
		}
nextgroup:
		group = group->next;
	} while (group != sd->groups);

	if (!busiest || this_load >= max_load)
		goto out_balanced;

	avg_load = (SCHED_LOAD_SCALE * total_load) / total_pwr;

	if (this_load >= avg_load ||
			100*max_load <= sd->imbalance_pct*this_load)
		goto out_balanced;

	*imbalance = min(max_load - avg_load, avg_load - this_load);

	/* How much load to actually move to equalise the imbalance */
	*imbalance = (*imbalance * min(busiest->cpu_power, this->cpu_power))
				/ SCHED_LOAD_SCALE;

	if (*imbalance < SCHED_LOAD_SCALE - 1) {
		unsigned long pwr_now = 0, pwr_move = 0;
		unsigned long tmp;

		if (max_load - this_load >= SCHED_LOAD_SCALE*2) {
			*imbalance = 1;
			return busiest;
		}

		/*
		 * OK, we don't have enough imbalance to justify moving tasks,
		 * however we may be able to increase total CPU power used by
		 * moving them.
		 */

		pwr_now += busiest->cpu_power*min(SCHED_LOAD_SCALE, max_load);
		pwr_now += this->cpu_power*min(SCHED_LOAD_SCALE, this_load);
		pwr_now /= SCHED_LOAD_SCALE;

		/* Amount of load we'd subtract */
		tmp = SCHED_LOAD_SCALE*SCHED_LOAD_SCALE/busiest->cpu_power;
		if (max_load > tmp)
			pwr_move += busiest->cpu_power*min(SCHED_LOAD_SCALE,
							max_load - tmp);

		/* Amount of load we'd add */
		tmp = SCHED_LOAD_SCALE*SCHED_LOAD_SCALE/this->cpu_power;
		if (max_load < tmp)
			tmp = max_load;
		pwr_move += this->cpu_power*min(SCHED_LOAD_SCALE, this_load + tmp);
		pwr_move /= SCHED_LOAD_SCALE;

		/* Move if we gain another 8th of a CPU worth of throughput */
		if (pwr_move < pwr_now + SCHED_LOAD_SCALE / 8)
			goto out_balanced;

		*imbalance = 1;
		return busiest;
	}

	/* Get rid of the scaling factor, rounding down as we divide */
	*imbalance = (*imbalance + 1) / SCHED_LOAD_SCALE;

	return busiest;

out_balanced:
	if (busiest && (idle == NEWLY_IDLE ||
			(idle == IDLE && max_load > SCHED_LOAD_SCALE)) ) {
		*imbalance = 1;
		return busiest;
	}

	*imbalance = 0;
	return NULL;
}


000016e1 <find_busiest_group>: 16e1: 55 push %ebp 16e2: 89 e5 mov %esp,%ebp 16e4: 57 push %edi 16e5: 56 push %esi 16e6: 53 push %ebx 16e7: 83 ec 48 sub $0x48,%esp 16ea: c7 45 dc 00 00 00 00 movl $0x0,0xffffffdc(%ebp) 16f1: c7 45 e0 00 00 00 00 movl $0x0,0xffffffe0(%ebp) 16f8: 89 55 e8 mov %edx,0xffffffe8(%ebp) 16fb: 89 45 ec mov %eax,0xffffffec(%ebp) 16fe: 89 4d e4 mov %ecx,0xffffffe4(%ebp) 1701: 8b 40 04 mov 0x4(%eax),%eax 1704: c7 45 d4 00 00 00 00 movl $0x0,0xffffffd4(%ebp) 170b: c7 45 c8 00 00 00 00 movl $0x0,0xffffffc8(%ebp) 1712: 89 45 d8 mov %eax,0xffffffd8(%ebp) 1715: 89 c2 mov %eax,%edx 1717: c7 45 c4 00 00 00 00 movl $0x0,0xffffffc4(%ebp) 171e: c7 45 cc 00 00 00 00 movl $0x0,0xffffffcc(%ebp) 1725: c7 45 c0 00 00 00 00 movl $0x0,0xffffffc0(%ebp) 172c: 8b 5d e8 mov 0xffffffe8(%ebp),%ebx 172f: 8b 4d d8 mov 0xffffffd8(%ebp),%ecx 1732: 0f a3 59 04 bt %ebx,0x4(%ecx) 1736: 19 c9 sbb %ecx,%ecx 1738: a1 00 00 00 00 mov 0x0,%eax 173d: c7 45 d0 00 00 00 00 movl $0x0,0xffffffd0(%ebp) 1744: 89 4d bc mov %ecx,0xffffffbc(%ebp) 1747: 8b 4d d8 mov 0xffffffd8(%ebp),%ecx 174a: 23 41 04 and 0x4(%ecx),%eax 174d: 85 c0 test %eax,%eax 174f: 89 45 f0 mov %eax,0xfffffff0(%ebp) 1752: 0f 84 ca 00 00 00 je 1822 <find_busiest_group+0x141> 1758: 8d 75 f0 lea 0xfffffff0(%ebp),%esi 175b: b9 01 00 00 00 mov $0x1,%ecx 1760: 89 f7 mov %esi,%edi 1762: 89 f3 mov %esi,%ebx 1764: 31 c0 xor %eax,%eax 1766: f3 af repz scas %es:(%edi),%eax 1768: 74 06 je 1770 <find_busiest_group+0x8f> 176a: 8d 7f fc lea 0xfffffffc(%edi),%edi 176d: 0f bc 07 bsf (%edi),%eax 1770: 29 df sub %ebx,%edi 1772: c1 e7 03 shl $0x3,%edi 1775: 01 f8 add %edi,%eax 1777: 83 f8 1f cmp $0x1f,%eax 177a: 89 45 b0 mov %eax,0xffffffb0(%ebp) 177d: 0f 8f 57 02 00 00 jg 19da <find_busiest_group+0x2f9> 1783: bf 00 04 00 00 mov $0x400,%edi 1788: 89 7d b8 mov %edi,0xffffffb8(%ebp) 178b: 8b 5d bc mov 0xffffffbc(%ebp),%ebx 178e: 85 db test %ebx,%ebx 1790: 0f 84 4f 02 00 00 je 19e5 <find_busiest_group+0x304> 1796: 8b 55 b0 mov 0xffffffb0(%ebp),%edx 1799: 89 f8 mov %edi,%eax 179b: 03 04 95 00 00 00 00 add 0x0(,%edx,4),%eax 17a2: 8b 50 04 mov 0x4(%eax),%edx 17a5: 8b 40 08 mov 0x8(%eax),%eax 17a8: c1 e2 07 shl $0x7,%edx 17ab: 39 c2 cmp %eax,%edx 17ad: 0f 43 c2 cmovae %edx,%eax 17b0: 8b 4d b0 mov 0xffffffb0(%ebp),%ecx 17b3: 01 45 d0 add %eax,0xffffffd0(%ebp) 17b6: ba 20 00 00 00 mov $0x20,%edx 17bb: 83 c1 01 add $0x1,%ecx 17be: 89 f0 mov %esi,%eax 17c0: 83 45 c0 01 addl $0x1,0xffffffc0(%ebp) 17c4: e8 fc ff ff ff call 17c5 <find_busiest_group+0xe4> 17c9: 83 f8 1f cmp $0x1f,%eax 17cc: 89 45 b0 mov %eax,0xffffffb0(%ebp) 17cf: 7e ba jle 178b <find_busiest_group+0xaa> 17d1: 8b 4d c0 mov 0xffffffc0(%ebp),%ecx 17d4: 85 c9 test %ecx,%ecx 17d6: 0f 84 fe 01 00 00 je 19da <find_busiest_group+0x2f9> 17dc: 8b 5d d0 mov 0xffffffd0(%ebp),%ebx 17df: 8b 45 d8 mov 0xffffffd8(%ebp),%eax 17e2: 89 da mov %ebx,%edx 17e4: 01 5d cc add %ebx,0xffffffcc(%ebp) 17e7: c1 e2 07 shl $0x7,%edx 17ea: 8b 48 08 mov 0x8(%eax),%ecx 17ed: 89 d0 mov %edx,%eax 17ef: 01 4d c4 add %ecx,0xffffffc4(%ebp) 17f2: 31 d2 xor %edx,%edx 17f4: f7 f1 div %ecx 17f6: 8b 55 bc mov 0xffffffbc(%ebp),%edx 17f9: 85 d2 test %edx,%edx 17fb: 89 45 d0 mov %eax,0xffffffd0(%ebp) 17fe: 0f 85 c8 01 00 00 jne 19cc <find_busiest_group+0x2eb> 1804: 8b 5d d4 mov 0xffffffd4(%ebp),%ebx 1807: 39 5d d0 cmp %ebx,0xffffffd0(%ebp) 180a: 0f 86 b1 01 00 00 jbe 19c1 <find_busiest_group+0x2e0> 1810: 8b 45 d0 mov 0xffffffd0(%ebp),%eax 1813: 8b 55 d8 mov 0xffffffd8(%ebp),%edx 1816: 89 45 d4 mov %eax,0xffffffd4(%ebp) 1819: 89 55 e0 mov %edx,0xffffffe0(%ebp) 181c: 8b 4d ec mov 0xffffffec(%ebp),%ecx 181f: 8b 51 04 mov 0x4(%ecx),%edx 1822: 8b 4d d8 mov 0xffffffd8(%ebp),%ecx 1825: 8b 09 mov (%ecx),%ecx 1827: 39 d1 cmp %edx,%ecx 1829: 89 4d d8 mov %ecx,0xffffffd8(%ebp) 182c: 0f 85 f3 fe ff ff jne 1725 <find_busiest_group+0x44> 1832: 8b 45 e0 mov 0xffffffe0(%ebp),%eax 1835: 85 c0 test %eax,%eax 1837: 0f 84 64 01 00 00 je 19a1 <find_busiest_group+0x2c0> 183d: 8b 5d d4 mov 0xffffffd4(%ebp),%ebx 1840: 39 5d c8 cmp %ebx,0xffffffc8(%ebp) 1843: 0f 83 2d 01 00 00 jae 1976 <find_busiest_group+0x295> 1849: c1 65 cc 07 shll $0x7,0xffffffcc(%ebp) 184d: 31 d2 xor %edx,%edx 184f: 8b 45 cc mov 0xffffffcc(%ebp),%eax 1852: f7 75 c4 divl 0xffffffc4(%ebp) 1855: 39 45 c8 cmp %eax,0xffffffc8(%ebp) 1858: 89 c1 mov %eax,%ecx 185a: 0f 83 16 01 00 00 jae 1976 <find_busiest_group+0x295> 1860: 6b d3 64 imul $0x64,%ebx,%edx 1863: 8b 45 c8 mov 0xffffffc8(%ebp),%eax 1866: 8b 5d ec mov 0xffffffec(%ebp),%ebx 1869: 0f af 43 18 imul 0x18(%ebx),%eax 186d: 39 c2 cmp %eax,%edx 186f: 0f 86 01 01 00 00 jbe 1976 <find_busiest_group+0x295> 1875: 8b 45 d4 mov 0xffffffd4(%ebp),%eax 1878: 89 ca mov %ecx,%edx 187a: 29 c8 sub %ecx,%eax 187c: 2b 55 c8 sub 0xffffffc8(%ebp),%edx 187f: 39 c2 cmp %eax,%edx 1881: 0f 47 d0 cmova %eax,%edx 1884: 8b 45 e4 mov 0xffffffe4(%ebp),%eax 1887: 89 10 mov %edx,(%eax) 1889: 8b 5d e0 mov 0xffffffe0(%ebp),%ebx 188c: 8b 4b 08 mov 0x8(%ebx),%ecx 188f: 8b 5d dc mov 0xffffffdc(%ebp),%ebx 1892: 8b 43 08 mov 0x8(%ebx),%eax 1895: 39 c8 cmp %ecx,%eax 1897: 0f 47 c1 cmova %ecx,%eax 189a: 0f af c2 imul %edx,%eax 189d: 8b 55 e4 mov 0xffffffe4(%ebp),%edx 18a0: c1 e8 07 shr $0x7,%eax 18a3: 83 f8 7e cmp $0x7e,%eax 18a6: 89 02 mov %eax,(%edx) 18a8: 0f 87 03 01 00 00 ja 19b1 <find_busiest_group+0x2d0> 18ae: 8b 45 d4 mov 0xffffffd4(%ebp),%eax 18b1: c7 45 b4 00 00 00 00 movl $0x0,0xffffffb4(%ebp) 18b8: 2b 45 c8 sub 0xffffffc8(%ebp),%eax 18bb: 3d ff 00 00 00 cmp $0xff,%eax 18c0: 76 11 jbe 18d3 <find_busiest_group+0x1f2> 18c2: c7 02 01 00 00 00 movl $0x1,(%edx) 18c8: 8b 45 e0 mov 0xffffffe0(%ebp),%eax 18cb: 83 c4 48 add $0x48,%esp 18ce: 5b pop %ebx 18cf: 5e pop %esi 18d0: 5f pop %edi 18d1: 5d pop %ebp ........... /*the following is ignored*/

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.com/



-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux