Wednesday, May 25, 2011

Definition of Poll

So I was talking with a colleague the other day about my initial confusion over the function ibv_poll_cq() in Infiniband verbs. I initially thought/assumed that the function operated similarly to the poll() syscall and was a tad confused on where/how a timeout could be specified to ibv_poll_cq(). As I worked through things, I later realized the ibv_poll_cq() does not iterate, sleep, or wait for an event to occur. It returns immediately if any events are ready or not. It's similar in action to poll() with a timeout of 0.

My colleague and I then got into a discussion of the definition of "poll". My colleague comes from a bit more of a hardware background and considered "poll" to mean a singular check of a state (such as in a register). I on the other hand, perhaps coming from more of a generic systems background, had always considered "poll" to imply both the check of state and some waiting system with it (may it be via sleep, busy-wait, etc.). I asked my colleague how he would say he wants to check a state multiple times? He said, "That's a poll loop."

Another way to think of it, is suppose I had some generic function like:

poll_for_event()

Would the initial assumption be that this function blocks or does not block?

So I was curious about the definition and how it is used in the broader community. I started with an assumption that the term "poll" in Computer Science comes from "poll" in relation to voting. According to Websters the definition of poll is:
"a sampling or collection of opinions on a subject, taken from either a selected or a random group of persons, as for the purpose of analysis."
The question is, can "poll" be applied to a single individual or must it be applied to a group? For example, can you say, "I want to poll a person about this vote?" Naturally, I have no background in linguistics or philology, so I'm just going on a guess here. When speaking of "poll" and voting, I think it is synonymous with gathering the opinions of multiple people and the singular case makes no sense. Otherwise, a "poll" accomplishes nothing towards determing majority vote/opinion. So in my opinion, this might lend the definition of "poll" to include the waiting/loop/whatever instead of a single status check.

Now, "poll" can be twisted when moved into a different field (such as a "bug"). When I initially thought of the syscall poll(), I was thinking predominantly about how it returns to the user after a specified timeout and returns event statuses. However, perhaps it is not named "poll" for this reason. Perhaps it is named "poll" due to its management of multiple file descriptors. In some respect, poll() gathers the "opinions" of each of the file descriptors and records them. So it sort of matches the classic voting definition of poll above.

But this doesn't help our discussion. Lets go back to the case where we're talking about "polling" a state or status. Wikipedia says:
"Polling, or polled operation, in computer science, refers to actively sampling the status of an external device by a client program as a synchronous activity."
and
"Polling is sometimes used synonymously with busy-wait polling (busy waiting)."
Here, it is implied that "poll" implies active multiple-checking and not a singular check of a status. However, I notice that in the above definitions from Wikipedia it is "polling" and "polled", but not "poll". In fact, as I look around the web, virtually every definition or description of "polling" in reference to this topic is listed as "polling". With rare occasion is this topic discussed using "poll" or "to poll" or "polls" (discounting the situations where it appears people are referencing poll() specifically).

So does "poll" refer to a singular check or an active sampling? In all liklihood different niches of the technical community eventually came up with their own definitions/meanings. It's one of those funny things that just happens (Perhaps I'll write someday of the confusion I've had with colleagues over magic numbers). I bet it comes down to common programming scenarios and expectations. Lets go back to my imaginary function:

poll_for_event()

In some communities, such as network programmers or GUI programmers, the assumption might be that the function blocks. The reasoning is simple. Under most circumstances, there's not much to do until the function returns (e.g. http request arrives, GUI item is clicked). So a person in this community who says, "poll", you are likely to believe that you wait until an event occurs.

Then perhaps you have people in the kernel community, where you have many other things you would rather be doing if an event isn't ready. So the natural assumption is the function won't block.

No comments:

Post a Comment