LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2013, 06:43 AM   #1
veena hosur
LQ Newbie
 
Registered: Feb 2013
Posts: 13

Rep: Reputation: Disabled
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
 
Old 03-13-2013, 06:45 AM   #2
veena hosur
LQ Newbie
 
Registered: Feb 2013
Posts: 13

Original Poster
Rep: Reputation: Disabled
its very urget please reply me
 
Old 03-13-2013, 07:29 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
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 View Post
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).

Last edited by johnsfine; 03-13-2013 at 07:32 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: dereferencing pointer to incomplete type joyce092130 Programming 11 09-29-2012 10:06 AM
error: dereferencing pointer to incomplete type joyce092130 Programming 1 07-07-2012 10:57 AM
[SOLVED] error: dereferencing pointer to incomplete type in C Himalay Programming 9 07-07-2012 09:35 AM
dereferencing pointer to incomplete type sweetymobil Programming 7 06-22-2009 08:46 AM
error: dereferencing pointer to incomplete type ChullDouvre Programming 2 05-02-2007 01:16 AM


All times are GMT -5. The time now is 09:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration