LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   dereferencing pointer to an incomplete type (https://www.linuxquestions.org/questions/linux-newbie-8/dereferencing-pointer-to-an-incomplete-type-4175453891/)

veena hosur 03-13-2013 05:43 AM

dereferencing pointer to an incomplete type
 
Code:

#include <linux/fs.h>
#include <linux/init.h>
#include <linux/pid_namespace.h>
#include <linux/proc_fs.h>
#include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/seqlock.h>
#include <linux/timer.h>

#include <linux/module.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/kernel_stat.h>
#include <linux/netdevice.h>


MODULE_LICENSE("GPL");


#define FSHIFT          11              /* nr of bits of precision */
#define FIXED_1        (1<<FSHIFT)    /* 1.0 as fixed-point */
#define LOAD_INT(x) ((x) >> FSHIFT)
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)

#define per_cpu(var, cpu) \
                  (*SHIFT_PERCPU_PTR(&(var), per_cpu_offset(cpu)))

DECLARE_PER_CPU(struct rq, runqueues);

#define cpu_rq(cpu)  (&per_cpu(runqueues, (cpu)))

extern int nr_threads;
extern unsigned long avnrun[]; /* Load averages */
 
/* get_avenrun - get the load average array
 @loads: pointer to dest load array
 @offset: offset to add
 @shift: shift count to shift the result left
*/
extern void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
{
  loads[0] = (avenrun[0] + offset) << shift;
  loads[1] = (avenrun[1] + offset) << shift;
  loads[2] = (avenrun[2] + offset) << shift;
}

 /*nr_running:
  externally visible scheduler statistics: current number of runnable
  threads performed since bootup
 */
extern unsigned long nr_running(void)
 {
        unsigned long i, sum = 0;
       
        for_each_online_cpu(i)
                sum += cpu_rq(i)->nr_running;
 
        return sum;
 }
EXPORT_SYMBOL_GPL(nr_running);

 
/*calcualation of cpu load*/
static int loadavg_proc_show(struct seq_file *m, void *v)
{
  //unsigned long avnrun[3];
  get_avenrun(avnrun, FIXED_1/200, 0);
 
  seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu /%d %d\n",
              LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
              LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
              LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
              nr_threads,
            task_active_pid_ns(current)->last_pid);
  return 0;
}

/* single_open open the virtual file.when output time comes it will call
  loadavg_proc_show function*/

static int loadavg_proc_open(struct inode *inode, struct file *file)
{
    return single_open(file, loadavg_proc_show, NULL);
}

/*The operations  - read(), llseek(), and release() - are
  all implemented by the seq_file code itself. So a virtual file's
  file_operations structure */
static const struct file_operations loadavg_proc_fops = {
                .open        = loadavg_proc_open,
                .read        = seq_read,
                .llseek = seq_lseek,
                .release = single_release,
};

/*loading the module*/
static int __init proc_loadavg_init(void)
{
  proc_create("loadavg", 0, NULL, &loadavg_proc_fops);
  return 0;
}

/*unloading the module*/
static void __exit proc_loadavg_exit(void)
 {
    remove_proc_entry("loadavg", NULL);
 }

module_init(proc_loadavg_init);
module_exit(proc_loadavg_exit);

this is the perfect way of calculating cpuload in kernel mode.if yes i am getting dereferencing pointer to incomplete type error in sum += cpu_rq(i)->nr_running line please tell me the solution.if not tell me how to calculate

veena hosur 03-13-2013 05:45 AM

its very urget please reply me

johnsfine 03-13-2013 06:29 AM

That error message means you needed to include the .h file that defines the struct whose member you are accessing.

Between the macros and the incomplete code, I can't guess what struct that is, so I can't guess what .h file it is.
Maybe you know what struct you are accessing or maybe the error message tells you more than you quoted.

Quote:

Originally Posted by veena hosur (Post 4910621)
its very urget please reply me

Some experts here will resent a post like that enough that they will skip replying, even if they know the answer.

In my opinion, if the question was urgent FOR YOU, then YOU should have put a bit more effort into providing enough information to enable a better answer on the first try (rather than have me say I can't guess which struct you need the definition of included).


All times are GMT -5. The time now is 06:16 PM.