How to prevent gcc optimizing in kernel modules?
===

I'm trying to understand how can one disable code optimization for kernel modules when compiling with gcc.
I tried giving pragmas like this 

    #pragma optimize("",off)
    void rt_ct_use_cpu(unsigned long long n_cicle){
	    unsigned long long i;
	    for(i=0;i<n_cicle;i++);
    }
    #pragma optimize("",on)

But the compiler gives a warning saying that it is going to ignore those pragmas. I also tried making something that avoid the compiler to roll the loop like 

    void rt_ct_use_cpu(unsigned long long n_cicle){
	    unsigned long long i;
	    unsigned long long time=0;
	    unsigned long long timebase = rt_get_cpu_time_ns();
	    for(i=0;i<n_cicle;i++) {
		    time += rt_get_cpu_time_ns();
		    time -= timebase;
	    }
    }

but in this case it doesn't matter how long is the cicle (how big is n_cicle) the program will run always the same amount of time (few milliseconds)

Can you help me?