How do asynchronous calls à la `epoll` or `kqueue` work at the CPU (assembly) level?












0















I've recently been trying to wrap my brain around asynchronous I/O, that is, epoll() on Linux and kqueue() on FreeBSD; instead of creating multiple threads and using something like select(), you can create only one thread and still respond to many I/O events at once.



I've been trying to understand how this works at a deep level in the machine code, but have hit a brick wall. (Perhaps my Google-Fu is just lacking.) I can't seem to find any CPU instructions related to async I/O at all - so how does it work?










share|improve this question























  • not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like movs...

    – Ped7g
    Nov 22 '18 at 9:55






  • 3





    epoll, kqueue and select all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls.

    – Ross Ridge
    Nov 22 '18 at 10:35






  • 1





    There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet.

    – fuz
    Nov 22 '18 at 12:51






  • 1





    Fundamentally, asynchronous I/O is done with interrupts.

    – EOF
    Nov 22 '18 at 18:52
















0















I've recently been trying to wrap my brain around asynchronous I/O, that is, epoll() on Linux and kqueue() on FreeBSD; instead of creating multiple threads and using something like select(), you can create only one thread and still respond to many I/O events at once.



I've been trying to understand how this works at a deep level in the machine code, but have hit a brick wall. (Perhaps my Google-Fu is just lacking.) I can't seem to find any CPU instructions related to async I/O at all - so how does it work?










share|improve this question























  • not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like movs...

    – Ped7g
    Nov 22 '18 at 9:55






  • 3





    epoll, kqueue and select all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls.

    – Ross Ridge
    Nov 22 '18 at 10:35






  • 1





    There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet.

    – fuz
    Nov 22 '18 at 12:51






  • 1





    Fundamentally, asynchronous I/O is done with interrupts.

    – EOF
    Nov 22 '18 at 18:52














0












0








0








I've recently been trying to wrap my brain around asynchronous I/O, that is, epoll() on Linux and kqueue() on FreeBSD; instead of creating multiple threads and using something like select(), you can create only one thread and still respond to many I/O events at once.



I've been trying to understand how this works at a deep level in the machine code, but have hit a brick wall. (Perhaps my Google-Fu is just lacking.) I can't seem to find any CPU instructions related to async I/O at all - so how does it work?










share|improve this question














I've recently been trying to wrap my brain around asynchronous I/O, that is, epoll() on Linux and kqueue() on FreeBSD; instead of creating multiple threads and using something like select(), you can create only one thread and still respond to many I/O events at once.



I've been trying to understand how this works at a deep level in the machine code, but have hit a brick wall. (Perhaps my Google-Fu is just lacking.) I can't seem to find any CPU instructions related to async I/O at all - so how does it work?







assembly x86-64 epoll kqueue






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 9:11









Fredrick BrennanFredrick Brennan

4,41011742




4,41011742













  • not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like movs...

    – Ped7g
    Nov 22 '18 at 9:55






  • 3





    epoll, kqueue and select all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls.

    – Ross Ridge
    Nov 22 '18 at 10:35






  • 1





    There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet.

    – fuz
    Nov 22 '18 at 12:51






  • 1





    Fundamentally, asynchronous I/O is done with interrupts.

    – EOF
    Nov 22 '18 at 18:52



















  • not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like movs...

    – Ped7g
    Nov 22 '18 at 9:55






  • 3





    epoll, kqueue and select all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls.

    – Ross Ridge
    Nov 22 '18 at 10:35






  • 1





    There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet.

    – fuz
    Nov 22 '18 at 12:51






  • 1





    Fundamentally, asynchronous I/O is done with interrupts.

    – EOF
    Nov 22 '18 at 18:52

















not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like movs...

– Ped7g
Nov 22 '18 at 9:55





not sure if I understand correctly what you mean by "asynchronous I/O", I'm afraid on assembly level it could lead one to completely different things than when used in context of epoll/kqueue, which seems to me more like queues with kernel/user boundary crossing (and the content like file handle can be also pretty much anything, the particular I/O done on it, or the event triggering its inclusion into queue can be anything, and if we are talking about block devices, it's probably up to the driver to define those). So the inner implementation of the queues in assembly is probably like movs...

– Ped7g
Nov 22 '18 at 9:55




3




3





epoll, kqueue and select all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls.

– Ross Ridge
Nov 22 '18 at 10:35





epoll, kqueue and select all do the same thing, they wait for events, just with different interfaces. Also none of them asynchronous calls themselves, but can be used to wait for events that result from asynchronous calls.

– Ross Ridge
Nov 22 '18 at 10:35




1




1





There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet.

– fuz
Nov 22 '18 at 12:51





There is nothing special going on on the machine code level. The operating system does the IO at some time and you can ask if it's done yet.

– fuz
Nov 22 '18 at 12:51




1




1





Fundamentally, asynchronous I/O is done with interrupts.

– EOF
Nov 22 '18 at 18:52





Fundamentally, asynchronous I/O is done with interrupts.

– EOF
Nov 22 '18 at 18:52












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427352%2fhow-do-asynchronous-calls-%25c3%25a0-la-epoll-or-kqueue-work-at-the-cpu-assembly-le%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427352%2fhow-do-asynchronous-calls-%25c3%25a0-la-epoll-or-kqueue-work-at-the-cpu-assembly-le%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy