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.

Tuesday, May 3, 2011

What is wrong with Albert Pujols?

Everyone that knows me knows I love Albert Pujols. He's the greatest baseball player of his generation and he plays for the St. Louis Cardinals. But what is wrong with him? Is he just in a prolonged slump? Look at these numbers through May 2nd.

.241 BA, .310 OBP, .438 SLG, .747 OPS

Compare to his career average of:

.330 BA, .424 OBP, .621 SLG, 1.045 OPS

I know in 2007, he started off the season very slowly hitting:

.250 BA, .343 OBP, .489 SLG, .832 OPS

but this is ridiculous. Is the pressure of his free agent year getting to him? If you take out the first 10 games of the season, where he was just awful, Albert Pujols is hitting:

.291 BA, .358 OBP, .500 SLG, .858 OPS

which is more reasonable. I suppose even the greatest players of all time will have slumps, look at what happened to Frank Thomas in 1998:

.265 BA, .381 OBP, .480 SLG, .861

This was after he hit:

.330 BA, .452 OBP, .600 SLG, 1.053 OPS

from 1990 to 1997.

I can only assume it's a slump, and it happens. If he wasn't hitting any home runs or getting any hits, then I suppose it'd be more concerning. But it appears even Albert Pujols can have a bit of a down year.

Update:

This blog entry (via Rob Neyer, via this post) suggests that Albert Pujols was injured and not letting on that he was injured. It's a good argument.

After 27 games without a home run (and hitting only a measly 4 doubles, seeing his slugging percentage drop from .512 to .409), Albert Pujols hit a home run on May 23. And then he hit 4 home runs between May 30th and June 4th. It's looking like that hamstring injury is all healed up.

Wednesday, April 20, 2011

A guilty pleasure ...

Back in college, I was a huge fan of the WWE and professional wrestling. Characters like Stone Cold Steve Austin, Kurt Angle, and the Dudley Boyz were hilarious. However, no one could top The Rock. To this day, it still amazes me how a character like The Rock was able to "electrify" (one of his catch phrases) and completely energize a crowd. Take a look at this clip:



(One of Booker T's catchphrases is to say "Sucka" all the time, so part of the lines above are mocking Booker T.)

It's amazing in the video above to see how The Rock compares to Chris Jericho. Chris Jericho has pretty good stage presence and is a pretty good speaker, however he isn't even in The Rock's league. It's no surprise he was able to translate it into a successful Hollywood career.

So I don't watch the WWE as much as I used to, but I still like to catch an episode of WWE Raw here and there. When I mention to my friends or colleages that I still like to watch wrestling once in awhile, they always tease with a remark of "Al, you know it's fake?"

It got me thinking of why I began liking the WWE in college. Part of it was the comedy, as the shows the WWE put on were entertaining by itself (it's not as good nowadays, characters like The Rock and Stone Cold were epicly good). However, a significant reason was the respect I gained for professional wrestling.

Just because wrestling is theater/an act, doesn't mean it's easy. It takes many of these guys years of training to perfect their craft to put on a good show. In fact, the WWE has a developmental league (i.e. a minor league system) for wrestlers before they can come up to the big time. In addition, just because professional wrestling is "not real", doesn't mean it doesn't hurt. Many of the moves and much of the "theater" still causes pain on wrestler's bodies. While many of the moves, when properly done, limit pain on the body, it doesn't eliminate it. When someone get's body slammed, they aren't falling on soft padding. A quote I heard once was something like:

"There's a trick to avoid a lot of pain/injury when getting hit by a steel folding chair. The trick is to use a steel folding chair instead of a baseball bat."

In other words, the steel folding chair is chosen because it won't cause serious damage. Things like baseball bats would cause actual injury.

Update

I found these videos of the Rock too, it's an amazing stage presence:



Monday, April 11, 2011

gcc extensions ...

Despite doing C programming for so many years, once in awhile some extension or really weird code makes me go "Huh?" I learned about a ternary operator extension the other day. The ternary operator is normally:

d = a ? b : c

but gcc allows

z = x ? : y

When I saw this, my immediate reaction was, "Uhhh, will that even compile?" What this extension allows is for x to be returned when the condition is true. So it's pretty much identical to:

z = x ? x : y

However, if x is an expression, it is only evaluated once. So there are some circumstances it could be quite useful. I felt sort of dumb when I didn't know it, but I felt better when multiple other co-workers didn't know this extension :-)

Sunday, April 10, 2011

Hmmmm ...

I saw an ad off LinkedIn for Saint Mary's College ...


It looked really familiar, then I realized it ...


Hmmm ...

Thursday, March 24, 2011

Yuja Wang

While we're on the topic of music stuff, I wandered upon this ...



and



Holy Cow!

Wednesday, March 23, 2011

Ocarinas

By some happenchance I wandered onto this video on YouTube the other day.



I thought it was pretty awesome. I like this other video game themed performance as well.



I noticed the ads on the video for stlocarina.com. I start clicking around, and sure enough, the website is partly owned by an old friend of mine in college, and her husband is playing the violin in the videos. It's a small world sometimes.