Skip to contentSkip to conversation

Quick Quiz B.13 help

Question Yubin Ruan 3 participants 10 messages Feb 13, 2017 – Feb 20, 2017

lore
Share & tools
lore

Yubin Ruan

author
#0 lore raw

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

regards,
Yubin Ruan

#1 lore raw
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler" completes.

Thanx, Paul

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

author
#2 lore raw
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

#3 lore raw
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?
Thanks, Akira

Quoted 35 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw
Quoted 38 lines · Akira Yokosawa
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

Quoted 6 lines

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

Yes.

Quoted 2 lines

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

True, up to a point. If CPU 1's lines 3-5 are in an interrupt handler, then the assert()'s condition only needs a compiler directive such as barrier() to keep things straight. If these are separate CPUs, then real memory barriers are required.

Quoted 4 lines

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

This doesn't change the meaning, but I take it that it is easier to read. But how about the following?

	The assertion must ensure that the load of ``e'' precedes that of
	``a''.
Quoted 5 lines

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?

And I should also call out that in the context of the quick quiz, there is only one CPU. How about the following?

Quick Quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, the code in all three columns of the table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level, so that the code in third column can be interrupted by the code in the first two columns. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples, for example, as follows:

while (b == 0) ;
smp_mb();
d = 1;
r1 = e;
barrier();
assert(r1 == 0 || a == 1);

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Thanx, Paul

Quoted 37 lines
Quoted 36 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
Quoted 67 lines · Paul E. McKenney
Quoted 38 lines · Akira Yokosawa
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

Quoted 6 lines

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

Yes.

Quoted 2 lines

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

True, up to a point. If CPU 1's lines 3-5 are in an interrupt handler, then the assert()'s condition only needs a compiler directive such as barrier() to keep things straight. If these are separate CPUs, then real memory barriers are required.

Quoted 4 lines

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

This doesn't change the meaning, but I take it that it is easier to read. But how about the following?

	The assertion must ensure that the load of ``e'' precedes that of
	``a''.
Quoted 8 lines
Quoted 5 lines

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?

And I should also call out that in the context of the quick quiz, there is only one CPU. How about the following?

Hmm, I thought there were still three CPUs involved in the quick quiz... If all the code runs on the same CPU, we don't need memory barriers, do we?

I thought what matter is (as said in the previous mail) lines 3-5 of CPU 2 can interrupt the assertion. Codes in columns 1 and 2 can still run on CPU 0 and 1 respectively.

Quoted 26 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, the code in all three columns of the table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level, so that the code in third column can be interrupted by the code in the first two columns. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples, for example, as follows:

while (b == 0) ;
smp_mb();
d = 1;
r1 = e;
barrier();
assert(r1 == 0 || a == 1);

Quoted 4 lines

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Here is my version of the quiz and answer:

Quick Quiz B.13:
Suppose that lines 3-5 for CPU 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, lines 3-5 for CPU 2 can interrupt the assertion of line 9. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the previous examples, for example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

Thoughts?

Thanks, Akira

Quoted 41 lines

Thanx, Paul

Quoted 37 lines
Quoted 36 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
Quoted 118 lines · Akira Yokosawa
Quoted 67 lines · Paul E. McKenney
Quoted 38 lines · Akira Yokosawa
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

Quoted 6 lines

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

Yes.

Quoted 2 lines

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

True, up to a point. If CPU 1's lines 3-5 are in an interrupt handler, then the assert()'s condition only needs a compiler directive such as barrier() to keep things straight. If these are separate CPUs, then real memory barriers are required.

Quoted 4 lines

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

This doesn't change the meaning, but I take it that it is easier to read. But how about the following?

	The assertion must ensure that the load of ``e'' precedes that of
	``a''.
Quoted 8 lines
Quoted 5 lines

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?

And I should also call out that in the context of the quick quiz, there is only one CPU. How about the following?

Hmm, I thought there were still three CPUs involved in the quick quiz... If all the code runs on the same CPU, we don't need memory barriers, do we?

I thought what matter is (as said in the previous mail) lines 3-5 of CPU 2 can interrupt the assertion. Codes in columns 1 and 2 can still run on CPU 0 and 1 respectively.

Quoted 26 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, the code in all three columns of the table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level, so that the code in third column can be interrupted by the code in the first two columns. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples, for example, as follows:

while (b == 0) ;
smp_mb();
d = 1;
r1 = e;
barrier();
assert(r1 == 0 || a == 1);

Quoted 4 lines

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Here is my version of the quiz and answer:

Quoted 7 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPU 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, lines 3-5 for CPU 2 can interrupt the assertion of line 9. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Given the discussion earlier in this thread, I believe that we do need to explicitly state that all of the code is running on a single CPU.

Quoted 10 lines

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the previous examples, for example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

I did do something very much like this with your Reported-by:

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples. For example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Thanx, Paul

Quoted 46 lines

Thoughts?

Thanks, Akira

Quoted 41 lines

Thanx, Paul

Quoted 37 lines
Quoted 36 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
Quoted 127 lines · Paul E. McKenney
Quoted 118 lines · Akira Yokosawa
Quoted 67 lines · Paul E. McKenney
Quoted 38 lines · Akira Yokosawa
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

Quoted 6 lines

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

Yes.

Quoted 2 lines

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

True, up to a point. If CPU 1's lines 3-5 are in an interrupt handler, then the assert()'s condition only needs a compiler directive such as barrier() to keep things straight. If these are separate CPUs, then real memory barriers are required.

Quoted 4 lines

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

This doesn't change the meaning, but I take it that it is easier to read. But how about the following?

	The assertion must ensure that the load of ``e'' precedes that of
	``a''.
Quoted 8 lines
Quoted 5 lines

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?

And I should also call out that in the context of the quick quiz, there is only one CPU. How about the following?

Hmm, I thought there were still three CPUs involved in the quick quiz... If all the code runs on the same CPU, we don't need memory barriers, do we?

I thought what matter is (as said in the previous mail) lines 3-5 of CPU 2 can interrupt the assertion. Codes in columns 1 and 2 can still run on CPU 0 and 1 respectively.

Quoted 26 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, the code in all three columns of the table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level, so that the code in third column can be interrupted by the code in the first two columns. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples, for example, as follows:

while (b == 0) ;
smp_mb();
d = 1;
r1 = e;
barrier();
assert(r1 == 0 || a == 1);

Quoted 4 lines

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Here is my version of the quiz and answer:

Quoted 7 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPU 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, lines 3-5 for CPU 2 can interrupt the assertion of line 9. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Quoted 2 lines

Given the discussion earlier in this thread, I believe that we do need to explicitly state that all of the code is running on a single CPU.

Well, I'm afraid I still can't see your point. Maybe I'm missing something important.
Let me ask a few questions regarding your version of the Quiz

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level.

In this part, you are saying lines 3-5 for CPUs 1 and 2 are in an interrupt handler.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In other words, the code in all three columns of the
table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level,

In this part, you are saying code for CPUs 0 and 1 runs in an interrupt handler, and lines 3-5 for CPU 2 as well as the assertion runs at process level.

I'm confused...

And again, I want to know what I said previously is correct or not:

Quoted 2 lines
Quoted 2 lines

If all the code runs on the same CPU, we don't need memory barriers, do we?

Am I missing something?

BTW, it seems you have not pushed your update.

Thanks, Akira

Quoted 79 lines
Quoted 11 lines

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the previous examples, for example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

I did do something very much like this with your Reported-by:

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples. For example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Thanx, Paul

Quoted 46 lines

Thoughts?

Thanks, Akira

Quoted 41 lines

Thanx, Paul

Quoted 37 lines
Quoted 36 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
Quoted 142 lines · Akira Yokosawa
Quoted 127 lines · Paul E. McKenney
Quoted 118 lines · Akira Yokosawa
Quoted 67 lines · Paul E. McKenney
Quoted 38 lines · Akira Yokosawa
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

Quoted 6 lines

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

Yes.

Quoted 2 lines

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

True, up to a point. If CPU 1's lines 3-5 are in an interrupt handler, then the assert()'s condition only needs a compiler directive such as barrier() to keep things straight. If these are separate CPUs, then real memory barriers are required.

Quoted 4 lines

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

This doesn't change the meaning, but I take it that it is easier to read. But how about the following?

	The assertion must ensure that the load of ``e'' precedes that of
	``a''.
Quoted 8 lines
Quoted 5 lines

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?

And I should also call out that in the context of the quick quiz, there is only one CPU. How about the following?

Hmm, I thought there were still three CPUs involved in the quick quiz... If all the code runs on the same CPU, we don't need memory barriers, do we?

I thought what matter is (as said in the previous mail) lines 3-5 of CPU 2 can interrupt the assertion. Codes in columns 1 and 2 can still run on CPU 0 and 1 respectively.

Quoted 26 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, the code in all three columns of the table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level, so that the code in third column can be interrupted by the code in the first two columns. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples, for example, as follows:

while (b == 0) ;
smp_mb();
d = 1;
r1 = e;
barrier();
assert(r1 == 0 || a == 1);

Quoted 4 lines

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Here is my version of the quiz and answer:

Quoted 7 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPU 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, lines 3-5 for CPU 2 can interrupt the assertion of line 9. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Quoted 2 lines

Given the discussion earlier in this thread, I believe that we do need to explicitly state that all of the code is running on a single CPU.

Well, I'm afraid I still can't see your point. Maybe I'm missing something important.
Let me ask a few questions regarding your version of the Quiz

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level.

In this part, you are saying lines 3-5 for CPUs 1 and 2 are in an interrupt handler.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In other words, the code in all three columns of the
table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level,

In this part, you are saying code for CPUs 0 and 1 runs in an interrupt handler, and lines 3-5 for CPU 2 as well as the assertion runs at process level.

The code in the CPUs 0 and 1 columns of the table not only runs in an interrupt handler, it also runs on CPU 2.

Quoted 6 lines

I'm confused...

And again, I want to know what I said previously is correct or not:

Quoted 2 lines
Quoted 2 lines

If all the code runs on the same CPU, we don't need memory barriers, do we?

No memory-barrier instructions, correct, give or take Itanium and SPARC RMO. Compiler directives (such as barrier() from the Linux kernel) are still needed.

Quoted 3 lines

Am I missing something?

BTW, it seems you have not pushed your update.

You are right! I just now pushed it.

Thanx, Paul

Quoted 82 lines

Thanks, Akira

Quoted 79 lines
Quoted 11 lines

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the previous examples, for example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

I did do something very much like this with your Reported-by:

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples. For example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Thanx, Paul

Quoted 46 lines

Thoughts?

Thanks, Akira

Quoted 41 lines

Thanx, Paul

Quoted 37 lines
Quoted 36 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#9 lore raw
Quoted 147 lines · Paul E. McKenney
Quoted 146 lines · Akira Yokosawa
Quoted 127 lines · Paul E. McKenney
Quoted 118 lines · Akira Yokosawa
Quoted 67 lines · Paul E. McKenney
Quoted 38 lines · Akira Yokosawa
Quoted 23 lines · Yubin Ruan
Quoted 18 lines · Paul E. McKenney
Quoted 10 lines · Yubin Ruan

Quick quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an
interrupt handler, and that the CPU 2's line 9 is running at process level. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

I can not come up with any practical material for this quiz, because I don't really know the implication of "in an interrupt handler", and "running in process level".

Quoted 6 lines

The answer hints that one would need to ensure that the load of "e" precedes that of "a" and hint the Linux kernel implementation "barrier()". But how is that exactly? I am going to invest some time into the Linux kernel implementation. But I would really appreciate some hints about this, as I don't have so much kernel development experience before.

Quoted 4 lines

I suggest reading an operating-system textbook. The ones I have are quite old, but here they are anyway in bibtex format. There are probably newer editions of some of them. The short answer on interrupts is that they force process-level processing to pause while the "interrupt handler"

Quoted 8 lines
                                          ~~~~~
                                          until ?
Quoted 4 lines

completes.

Thanx, Paul

Actually I have taken a operating system course and know about interrupt handler. Maybe I don't understand the concepts well. I don't really get your point here. If you have time, maybe you can provide me more information, otherwise I would just have to investigate more on this myself. Thanks.

Hi Paul,

Prompted by Yubin's question, I looked into the Quick Quiz. And I have a theory what you wanted to say.

Quoted 6 lines

First of all, the "assert()" has a line number of 9, but the execution order of lines 3-5 and the assertion on CPU 2 does not matter in Table B.4, doesn't it?

Your point here looks like that lines 3-5 for CPU 2 can interrupt the assert().

Yes.

Quoted 2 lines

If this is the case, whether lines 3-5 for CPU 1 are in an interrupt handler or not does not matter, I suppose.

True, up to a point. If CPU 1's lines 3-5 are in an interrupt handler, then the assert()'s condition only needs a compiler directive such as barrier() to keep things straight. If these are separate CPUs, then real memory barriers are required.

Quoted 4 lines

And the first sentence of Answer of the Quick Quiz should read:

The assertion will need to be written so that the load of ``e'' is assured to precede that of ``a''.

This doesn't change the meaning, but I take it that it is easier to read. But how about the following?

	The assertion must ensure that the load of ``e'' precedes that of
	``a''.
Quoted 8 lines
Quoted 5 lines

The second sentence mentions the barrier() primitive. It is effective because interrupts should see the sequence of instructions in order even if they are executed out-of-order.

Am I missing something?

And I should also call out that in the context of the quick quiz, there is only one CPU. How about the following?

Hmm, I thought there were still three CPUs involved in the quick quiz... If all the code runs on the same CPU, we don't need memory barriers, do we?

I thought what matter is (as said in the previous mail) lines 3-5 of CPU 2 can interrupt the assertion. Codes in columns 1 and 2 can still run on CPU 0 and 1 respectively.

Quoted 26 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, the code in all three columns of the table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level, so that the code in third column can be interrupted by the code in the first two columns. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples, for example, as follows:

while (b == 0) ;
smp_mb();
d = 1;
r1 = e;
barrier();
assert(r1 == 0 || a == 1);

Quoted 4 lines

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Here is my version of the quiz and answer:

Quoted 7 lines

Quick Quiz B.13:
Suppose that lines 3-5 for CPU 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level. In other words, lines 3-5 for CPU 2 can interrupt the assertion of line 9. What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Quoted 2 lines

Given the discussion earlier in this thread, I believe that we do need to explicitly state that all of the code is running on a single CPU.

Well, I'm afraid I still can't see your point. Maybe I'm missing something important.
Let me ask a few questions regarding your version of the Quiz

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Suppose that lines 3-5 for CPUs 1 and 2 in Table B.4 are in an interrupt handler, and that the CPU 2’s line 9 runs at process level.

In this part, you are saying lines 3-5 for CPUs 1 and 2 are in an interrupt handler.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

In other words, the code in all three columns of the
table runs on the same CPU, but the first two columns run in an interrupt handler, and the third column runs at process level,

Quoted 7 lines
Quoted 3 lines

In this part, you are saying code for CPUs 0 and 1 runs in an interrupt handler, and lines 3-5 for CPU 2 as well as the assertion runs at process level.

The code in the CPUs 0 and 1 columns of the table not only runs in an interrupt handler, it also runs on CPU 2.

So, you mean something like the following? (the Quick Quiz is getting longer...)

Quick Quiz B.13:
Suppose that code for CPUs 0 and 1 and lines 3-5 for CPU 2 in Table B.4 are also in interrupt handlers and can be executed on CPU 2, and all the code in the Table still runs at process level on respective CPUs.
In other words, the code in all three columns of the table can run on the same CPU (CPU 2). In this case the code in the third column can be interrupted by the code in the first two columns and lines 3-5 for CPU 2.
What changes, if any, are required to enable the code to work correctly, in other words, to prevent the assertion from firing?

Looks somewhat redundant, but wordsmith can wait.
I used plural form of "interrupt handlers" because if all of them are in a single interrupt handler, their execution order in the handler is defined by the instruction order in the handler, and possible variation of ordering is reduced.

And it should be regarded as a bad design pattern to use four polling loops within an interrupt handler...

I might still be seeing some different picture from yours.

Quoted 10 lines
Quoted 6 lines

I'm confused...

And again, I want to know what I said previously is correct or not:

Quoted 2 lines
Quoted 2 lines

If all the code runs on the same CPU, we don't need memory barriers, do we?

No memory-barrier instructions, correct, give or take Itanium and SPARC RMO. Compiler directives (such as barrier() from the Linux kernel) are still needed.

So, Itanium and SPARC RMO does require memory-barriers in such a case. Whew.

Anyway, I get that three CPUs are still involved in this Quick Quiz and we need memory barriers.

Thanks, Akira

Quoted 93 lines
Quoted 4 lines

Am I missing something?

BTW, it seems you have not pushed your update.

You are right! I just now pushed it.

Thanx, Paul

Quoted 82 lines

Thanks, Akira

Quoted 79 lines
Quoted 11 lines

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the previous examples, for example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

I did do something very much like this with your Reported-by:

Answer:
The assertion must ensure that the load of “e” precedes that of “a”. In the Linux kernel, the barrier() primitive may be used to accomplish this in much the same way that the memory barrier was used in the assertions in the previous examples. For example, the assertion can be modified as follows:

r1 = e;
barrier();
assert(r1 == 0 || a == 1);

No changes are needed to the code in the first two columns, because interrupt handlers run atomically from the perspective of the interrupted code.

Thanx, Paul

Quoted 46 lines

Thoughts?

Thanks, Akira

Quoted 41 lines

Thanx, Paul

Quoted 37 lines
Quoted 36 lines

regards,
Yubin Ruan

Quoted 25 lines

------------------------------------------------------------------------

@book{CorbetRubiniKroahHartman
,author="Jonathan Corbet and Alessandro Rubini and Greg Kroah-Hartman" ,title="Linux Device Drivers"
,publisher="O'Reilly Media, Inc."
,year="2005"
,edition="Third"
}

@book{Silberschatz98a
,author="Abraham Silberschatz and Peter Baer Galvin" ,title="Operating System Concepts" ,publisher="Addison-Wesley"
,year="1998"
,edition="Fifth"
}

@book{Vahalia96
,author="Uresh Vahalia"
,title="{UNIX} Internals: The New Frontiers"
,publisher="Prentice Hall"
,year="1996"
}

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe perfbook" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html