lkml.org 
[lkml]   [2004]   [Jan]   [7]   [last100]   RSS Feed
Views: [more markup]   [less markup]   [headers]   [forward]  
 
Messages in this thread
/
DateWed, 07 Jan 2004 05:04:28 +1100
Fromsena <>
Subjectuid-task_struct Code after Proper Naming and indentation
Hi Robin,

ps way of reading uid is good.

 Though they are in 2 differant modes (kernel and user)

 Will that be a problem?

Herewith I am sending to you the code after proper indentation.

In timer.c file I have included and then updated all the neccessary 
functions else where accordingly.

unsigned long numof_root_tasks;    //for root uid<500, I am getting this 
uidArray[0] is for storing uid (assumed 100 for all <500)
unsigned long numof_uid500_tasks;    //for 500
unsigned long numof_uid501_tasks;    //for 501
unsigned long numof_uid502_tasks;    //for 502
unsigned long numof_uid503_tasks;    //for 503
unsigned long numof_uid504_tasks;    // for 504
unsigned int uidArray[7];

static unsigned long
count_active_tasks(void)
{
    struct task_struct *p;
    unsigned long nr = 0;
    int s = 0;
    int i = 0;
    int j = 0;
    int k = 0;
    int m = 0;


    read_lock(&tasklist_lock);

    for_each_task(p) {
        if ((p->state == TASK_RUNNING ||
             (p->state & TASK_UNINTERRUPTIBLE))) {
            nr += FIXED_1;    //nr total tasks
            if (i == 0) {
                uidArray[0] = 100;
                if (p->uid < 500) {
                    numof_root_tasks += FIXED_1;
                } else {
                    uidArray[1] = p->uid;
                    numof_uid500_tasks += FIXED_1;
                    k++;
                }
                k++;
            } else {
                for (j = 0; j < k; j++) {
                    if ((j == 0) && (p->uid < 500)
                        && (s == 0)) {
                        numof_root_tasks +=
                            FIXED_1;
                        s = 1;
                        break;
                    } else if ((uidArray[j] == p->uid)
                           && s == 0) {
                        if (j == 1) {
                            numof_uid500_tasks
                                += FIXED_1;
                        }
                        if (j == 2) {
                            numof_uid501_tasks
                                += FIXED_1;
                        }
                        if (j == 3) {
                            numof_uid502_tasks
                                += FIXED_1;
                        }
                        if (j == 4) {
                            numof_uid503_tasks
                                += FIXED_1;
                        }
                        if (j == 5) {
                            numof_uid504_tasks
                                += FIXED_1;
                        }
                        s = 1;
                        break;
                    }
                }
                if (s == 0) {
                    if (k < 6) {
                        k++;
                        j = k - 1;
                        uidArray[j] = p->uid;
                        if (j == 1) {
                            numof_uid500_tasks
                                += FIXED_1;
                        }
                        if (j == 2) {
                            numof_uid501_tasks
                                += FIXED_1;
                        }
                        if (j == 3) {
                            numof_uid502_tasks
                                += FIXED_1;
                        }
                        if (j == 4) {
                            numof_uid503_tasks
                                += FIXED_1;
                        }
                        if (j == 5) {
                            numof_uid504_tasks
                                += FIXED_1;
                        }
                    }
                }
                s = 0;
            }
            i++;
        }
    }
    read_unlock(&tasklist_lock);
    return nr;
}
unsigned long avenrun[6];

unsigned long avenrunT;

static inline void
calc_load(unsigned long ticks)
{
    unsigned long active_tasks;    /*fixed-point */
    static int count = LOAD_FREQ;
    count -= ticks;
    if (count < 0) {
        count += LOAD_FREQ;
        active_tasks = count_active_tasks();
        CALC_LOAD(avenrunT, EXP_5, active_tasks);
        CALC_LOAD(avenrun[0], EXP_5, numof_root_tasks);
        CALC_LOAD(avenrun[1], EXP_5, numof_uid500_tasks);
        CALC_LOAD(avenrun[2], EXP_5, numof_uid501_tasks);
        CALC_LOAD(avenrun[3], EXP_5, numof_uid502_tasks);
        CALC_LOAD(avenrun[4], EXP_5, numof_uid503_tasks);
        CALC_LOAD(avenrun[5], EXP_5, numof_uid504_tasks);
    }
}
Thanks
Sena Seneviratene
Computer Engineering Lab
Sydney University









-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:59    [from the cache]
©2003-2008