[original file is 20070831CELF_Busybox.pdf]
[translated by ikoma]


CELF Technical Jamboree #16
Aug. 31, 2007


© Hitachi, Ltd. 2007. All rights reserved.

OProfile Porting to MIPS Architecture



8/31/2007

Takehiko Nagano
Embedded System Platform Research Laboratory
Hitachi, Ltd.


© Hitachi, Ltd. 2007. All rights reserved.

OProfile Porting to MIPS Architecture

* Contents


© Hitachi, Ltd. 2007. All rights reserved. 2

Overview of Oprofile

* Tool to Measure System Performance


© Hitachi, Ltd. 2007. All rights reserved. 3

Overview of OProfile

[See original file for figure]

OProfile output example

root@tx4937:~# opreport --symbols
CPU: MIPS TX4937, speed 0 MHz (estimated)
Counted H_W_TIMER_2 events
(H_W_TIMER2_INTERRUPTS) with a unit mask of 0x00 (No
unit mask) count 100000
samples % app name symbol name
14685 96.1627 vmlinux r4k_wait
92 0.6024 vmlinux r4k_blast_icache
27 0.1768 vmlinux r4k_copy_page_d32
22 0.1441 vmlinux
r4k_blast_dcache_page
21 0.1375 vmlinux r4k_blast_dcache
20 0.1310 vmlinux ne_block_input
15 0.0982 bash internal_malloc
12 0.0786 ld-2.3.2.so _dl_lookup_symbol
11 0.0720 ld-2.3.2.so
_dl_lookup_versioned_symbol
11 0.0720 vmlinux serial_console_write
10 0.0655 vmlinux ne_block_output

+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
|                               +==============+                              |
                                |OProfile data||-----------\
|  +------------+               +-------------+             \                 |
   |kernel image|                     ^                      V
|  +------------+                     |               +----------------+      |
   +------------+    func      +---------------+      |    OProfile    |   
|  | app image  |    addr      |OProfile daemon|<---- |control/analysis|      |
   +------------+              +---------------+      |    commands    |
|                                                     +----------------+      |
      ==================
+ - // /proc/pid/maps  /- - - - - - - - - - - - - - - - - - - - - - - - - - - +
+--//                 /-------------------------------------------------------+
|   ------------------                                          Linux Kernel  |
|  +---+                     +----------------+       +-----+                 |
|  |pid|======sampling======>|OProfile modules|<=====>|Buffer|                |
|  +---+                     +----------------+       +-----+                 |
|                        ^        ^                                           |
+----------------------     sampling   ---------------------------------------+
+-----------------------||--------|-------------------------------------------+
|                       ||   +----|--------+                         CPU      |
|                            |    timer    |                                  |
|                +--------+  | +---------+ |                                  |
|                |PC value|  | |interrupt| |                                  |
|                +--------+  | +---------+ |                                  |
|                            +-------------+                                  |
|                                                                             |
+-----------------------------------------------------------------------------+

              Figure 1. Configuration and output example of OProfile


© Hitachi, Ltd. 2007. All rights reserved. 4

Background of Porting OProfile

* No Profiler Available which Satisfies Embedded System Developers' Needs


© Hitachi, Ltd. 2007. All rights reserved. 5

Porting Policy of OProfile

* Port only basic functions of OProfile

* Higher sampling rate


© Hitachi, Ltd. 2007. All rights reserved. 6

OProflie Supporting Status

* OProfile Availability

+----------+----------+----------+----------+----------+----------+
|          |   i386   |  x86-64  |   arm    |    sh    |   mips   |
+----------+----------+----------+----------+----------+----------+
| Kernel   | athlon   | YES      | xscale   | SH7750S  | mips32   |
| 2.6.20   | p4       |          |          | SH7750   | mips64   |
|          | ppro     |          |          | SH7091   | R10000   |
|          | x86      |          |          |          | SB1      |
|          |          |          |          |          | RM9000   |
+----------+----------+----------+----------+----------+----------+
| Kernel   | YES      | YES      | NO       | NO       | mips64   |
| 2.4.x    |          |          |          |          | r5k      |
+----------+----------+----------+----------+----------+----------+
| Kernel   | YES      | YES      | NO       | NO       | NO       |
| 2.2.x    |          |          |          |          |          |
+----------+----------+----------+----------+----------+----------+
                               Embedded platforms have not been well supported
     Table 1. OProfile support status


© Hitachi, Ltd. 2007. All rights reserved. 7

What were Ported?

* Where work is required to port:


© Hitachi, Ltd. 2007. All rights reserved. 8

What were Ported?

* Source Code Required to Add or Modify


© Hitachi, Ltd. 2007. All rights reserved. 9

== What were Ported? Implementing Interrupt Handler==

* Interrupt Handler etc.


© Hitachi, Ltd. 2007. All rights reserved. 10

== What were Ported? Implementing Interrupt Handler==

* Timer Initialization and Start

+---+---------+--------+---------------------------------+-----+--------------------------+
| # |register |   item |       name                      |value| content                  |
+---+---------+--------+---------------------------------+-----+--------------------------+
| 1 | TMTCR2  | TCE    | Timer Counter Enable            |  1  | ON                       |
| 2 |         | CCDE   | Counter Clock Duration Enable   |  1  | ON                       |
| 3 |         | CRE    | Counter Reset Enable            |  1  | Reset                    |
| 4 |         | CCS    | Counter Clock Selection         |  1  | Use                      |
| 5 |         | TMODE  | Timer Mode                      |  0  | Use interval timer mode  |
| 6 | TMTISR2 |        |                                 |     |                          |
| 7 | TMCPRA2 |TMCCPRA2| Timer 2 Compare Register        |33000| Interrupt every 1msec    |
| 8 | TMITMR2 | TTIE   | Interval Timer IMCPRA interrupt |  1  | ON                       |
| 9 |         | TZCE   | Interval Timer Clear Permission |  1  | Allow                    |
+---+---------+--------+---------------------------------+-----+--------------------------+
   Table 2. Registers necessary for tiemer invocation (in case of 1 msec interrupt period)


© Hitachi, Ltd. 2007. All rights reserved. 11

== What were Ported? Implementing Interrupt Handler==

#define TX4937_TMR_SET(ofs,val) ( TX4927_WR32(TX4927_BASE + ofs , val) )
#define TX4937_TMR_RD(ofs) (TX4927_RD32(TX4927_BASE + ofs ))
static int timer_setup(void)
{
    TX4937_TMR_SET(TX4927_TMR2_TMTCR2, (0x1 << 7 | 0x1 << 6 | 0x1 << 5 | 0x0 << 2 |
 0x0 << 1 | 0x0 ));
    //TWIS,TPIBS,TPIAS and TIIS default
    TX4937_TMR_SET( TX4927_TMR2_TMTISR2, 0);
    TX4937_TMR_SET( TX4927_TMR2_TMCCDR2,0);
  //interrupt timing counter value ....
    TX4937_TMR_SET( TX4927_TMR2_TMCPRA2, 33000);
    return 0;
}
static void timer_start(void)
{
    u32 temp;

    //TTIE and TZCE are on
    TX4937_TMR_SET( TX4927_TMR2_TMITMR2 , 0x1 << 15 | 0x1 );
    temp = (TX4937_TMR_RD( TX4927_TMR2_TMTCR2 ) & ~(0x1 << 5));
    TX4937_TMR_SET( TX4927_TMR2_TMTCR2,temp );
    TX4937_TMR_SET( TX4927_TMR2_TMTCR2, temp | (0x1 << 7 ) );
        //counte clock divide
}


© Hitachi, Ltd. 2007. All rights reserved. 12

== What were Ported? Implementing Interrupt Handler==

* Obtaining Program Counter Value

static void do_timer_interrupt(int irq, void * dev_id, struct pt_regs * regs)
{
    uint cpu = op_cpu_id();
    int usermode = user_mode(regs);
    /* Reset the interrupt */
    TX4937_TMR_SET( TX4927_TMR2_TMTISR2,0 );   // <===
    if ((sysctl.ctr[0].kernel && usermode)
        || (sysctl.ctr[0].user && !usermode))
        return;
    read_lock( &current->files->file_lock );
    op_do_profile(cpu, instruction_pointer(regs), IRQ_ENABLED(regs), 0);  // <===
    read_unlock( &current->files->file_lock );
}


© Hitachi, Ltd. 2007. All rights reserved. 13

What were Ported? Modifying System Calls

* Build /module/mips/op_syscall.c

+---+---------------+----------------------------+------------------------------------------+
| # |name of        | function to get info       | note                                     |
|   | system call   |                            |                                          |
+---+---------------+----------------------------+------------------------------------------+
| 1 | clone         | oprof_report_fork          |                                          |
| 2 | execve        | oprof_output_map           | Register refferred is different          |
| 3 | exit          | oprof_put_note             |                                          |
| 4 | fork          | oprof_report_fork          |                                          |
| 5 | init_module   | oprof_put_note             |                                          |
| 6 | mmap          | oprof_output_map           | there is an interface as sys_old_mmap,   |
|   |               |                            | but it is internally do_mmap2;           |
|   |               |                            | interfaces for mips and x86 are not same |
| 7 | mmap2         | oprof_output_map           |                                          |
| 8 | vfork         | oprof_report_fork          | not used in mips kernel                  |
+---+---------------+----------------------------+------------------------------------------+
                     Table 3. System calls which requres to be fixed


© Hitachi, Ltd. 2007. All rights reserved. 14

What were Ported? Modifying System Calls

* How to Replace System Calls


© Hitachi, Ltd. 2007. All rights reserved. 15

What were Ported? Modifying System Calls

* e.g. Modificaiton of sys_execve

asmlinkage static int my_sys_execve(struct pt_regs regs)
{
    int error;
    char * filename;

    MOD_INC_USE_COUNT;

    filename = getname((char *) (long)regs.regs[4]);            // For modification per each architecture,
    error = PTR_ERR(filename);                                  // see /arch/*/kernel/syscall.c
    if (IS_ERR(filename))                                       //
        goto out;                                               //
    error = do_execve(filename, (char **) (long)regs.regs[5],   //
        (char **) (long)regs.regs[6], &regs);                   //

    //output info                        // For timing and contents of data aquisition,
    if (!error) {                        // borrow from the source code for other architecture
        PTRACE_OFF(current);             //
        oprof_output_maps(current);      // <-- after oprof_output_maps, information for symbol
    }                                    //      resolution need not be modified

    putname(filename);

out:
    MOD_DEC_USE_COUNT;
    return error;
}


© Hitachi, Ltd. 2007. All rights reserved. 16

What were Ported? Others

* Specify CPU type

    { "NEC VR5432", "mips/vr5432", CPU_MIPS_VR5432, 2 },
    { "NEC VR5500", "mips/vr5500", CPU_MIPS_VR5500, 2 },
    { "MIPS TX4937", "mips/TX4937", CPU_MIPS_TX4937, 1},
    { "e500", "ppc/e500", CPU_PPC_E500, 4 },

* Build events file


© Hitachi, Ltd. 2007. All rights reserved. 17

What were Ported? Others

問題発生 * Trouble breaks out!

CFLAGS_op_syscalls.o += -DSYS_CALL_TABLE_ADDR=0x`$(CROSS_COMPILE)nm $(KSRC)/vmlinux
| grep sys_call_table | cut -f 1 -d ' '`


© Hitachi, Ltd. 2007. All rights reserved. 18

Summary

* Results


© Hitachi, Ltd. 2007. All rights reserved.

END

OProfile Porting to MIPS Architecture

8/31/2007 Takehiko Nagano Embedded System Platform Research Laboratory Hitachi, Ltd.


© Hitachi, Ltd. 2007. All rights reserved. 20

HITACHI Inspire the Next






Jamboree16OprofilePorting (last edited 2008-05-07 18:22:05 by localhost)