mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* uid-task_struct Code after Proper Naming and indentation
@ 2004-01-06 18:04 sena
  2004-01-07 17:12 ` Robin Holt
  0 siblings, 1 reply; 3+ messages in thread
From: sena @ 2004-01-06 18:04 UTC (permalink / raw)
  To: holt; +Cc: linux-kernel

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










^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-01-08  2:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-06 18:04 uid-task_struct Code after Proper Naming and indentation sena
2004-01-07 17:12 ` Robin Holt
2004-01-07  3:42   ` auntvini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome