3
Contributors
7
Replies
9
Views
7 Years
Discussion Span
Last Post by onus
0

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 by gerard4143: n/a

0

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?

0

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.

0

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 by sree_ec: n/a

1

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 by gerard4143: n/a

Votes + Comments
thanks :)
0

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?

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.