On this link http://lxr.ncu.cc/source/kernel/timer.c#094 a return type is defined

return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG);

What is the above function returning.I am not clear with definition of what is being returned in the above code.

To see what's just do some substitution...

#define TBASE_DEFERRABLE_FLAG (0x1)
struct tvec_base *base

First we cast base to unsigned long
(unsigned long)base

Then we perform the bit operation & on
(unsigned long)base & 0x1

Then we cast our result to
(unsigned long)(unsigned long)base & 0x1

Why do it this way? It may be a simple trick to manipulate the spinlock_t variable in

struct tvec_base {
         spinlock_t lock;
         struct timer_list *running_timer;
         unsigned long timer_jiffies;
         struct tvec_root tv1;
         struct tvec tv2;
         struct tvec tv3;
         struct tvec tv4;
         struct tvec tv5;
} ____cacheline_aligned;

Note I said 'may' be a way.

Edited 6 Years Ago by gerard4143: n/a

To see what's just do some substitution...

#define TBASE_DEFERRABLE_FLAG (0x1)
struct tvec_base *base

First we cast base to unsigned long
(unsigned long)base

Then we perform the bit operation & on
(unsigned long)base & 0x1

Then we cast our result to
(unsigned long)(unsigned long)base & 0x1

Why do it this way? It may be a simple trick to manipulate the spinlock_t variable in

struct tvec_base {
         spinlock_t lock;
         struct timer_list *running_timer;
         unsigned long timer_jiffies;
         struct tvec_root tv1;
         struct tvec tv2;
         struct tvec tv3;
         struct tvec tv4;
         struct tvec tv5;
} ____cacheline_aligned;

Note I said 'may' be a way.

Adding myself into this thread
Hi Gerard, Can you explain why do you think that it could be for manipulating the lock variable?

Actually I made the reply before coffee...These remarks indicate

/*
085 * Note that all tvec_bases are 2 byte aligned and lower bit of
086 * base in timer_list is guaranteed to be zero. Use the LSB for
087 * the new flag to indicate whether the timer is deferrable
088 */

That your masking out the bit of struct tvec_base *base with 0x1 and returning the value.

Actually I made the reply before coffee...These remarks indicate


That your masking out the bit of struct tvec_base *base with 0x1 and returning the value.

To get the LSB, 0xFF Should be used. Isnt it?

Edited 6 Years Ago by sree_ec: n/a

Because its aligned 2 bytes its guaranteed that the address & 0x1 will return 0...Check out the attached code..

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
	int i = 0;
	char __attribute__((aligned(2))) ch1;
	char *cptr = &ch1;

	for (i = 0; i < 20; ++i)	
	{
		fprintf(stdout, "ans->%u\n", ((unsigned int)(unsigned long)cptr & 0x1));
		cptr += 2;
	}


	exit(EXIT_SUCCESS);
}

The output is ans->0 for all iterations...Why do they have a function that tests for this? I really don't know.

Edited 6 Years Ago by gerard4143: n/a

Comments
thanks :)

Because its aligned 2 bytes its guaranteed that the address & 0x1 will return 0...Check out the attached code..

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
	int i = 0;
	char __attribute__((aligned(2))) ch1;
	char *cptr = &ch1;

	for (i = 0; i < 20; ++i)	
	{
		fprintf(stdout, "ans->%u\n", ((unsigned int)(unsigned long)cptr & 0x1));
		cptr += 2;
	}


	exit(EXIT_SUCCESS);
}

The output is ans->0 for all iterations...Why do they have a function that tests for this? I really don't know.

Yeah.. I understood what you meant. thanks..
Next question is slightly out of context.. But to finish this discussion off with no questions remain unanswered in my mind,
Do you know what is that new flag that they are talking about in the comment?

I could not understand any thing from your discussion.I am a learning programmer please explain in simple terms.I have programmed in normal C this sort of kernel C is new to me.

This article has been dead for over six months. Start a new discussion instead.