Saturday, 19 November 2016

Overcoming Stereotypes One Parent At A Time

I just got back from a children's sports club dinner where I hardly knew anyone and apparently I was seated with the other social leftovers. It turned out the woman next to me was very nice and we had a long conversation. She was excited to hear that I do computer science and software development, and mentioned that her daughter is starting university next year and strongly considering CS. I gave my standard pitch about why CS is a wonderful career path --- hope I didn't lay it on too thick. The daughter apparently is interested in computers and good at maths, and her teachers think she has a "logical mind", so that all sounded promising and I said so. But then the mother started talking about how that "logical mind" wasn't really a girly thing and asking whether the daughter might be better doing something softer like design. I pushed back and asked her not to make assumptions about what women and men might enjoy or be capable of, and mentioned a few of the women I've known who are extremely capable at hard-core CS. I pointed out that while CS isn't for everyone and I think people should try to find work they're passionate about, the demand and rewards are often greater for people in more technical roles.

This isn't the first time I've encountered mothers to a greater or lesser extent steering their daughters away from more technical roles. I've done a fair number of talks in high schools promoting CS careers, but at least for girls maybe targeting their parents somehow would also be worth doing.

I'll send this family some links to Playcanvas and other programming resources and hope that they, plus my sales pitch, will make a difference. One of the difficulties here is that you never know or find out whether what you did matters.

Thursday, 17 November 2016

Stop Saying "Xs Do Y" Disingenuously

I keep seeing inflammatory statements about members of some group where it's left deliberately unclear whether they mean some, most, or all members of the group.

For example, someone will tweet "Australians club baby penguins!" The intent is to encourage outrage against the malevolence of Australians. This is unjust (I guess), but if pressed the author will fall back on the defense that indeed more than one Australian is known to have bashed penguins and "that's all they meant".

To some extent they're exploiting a defect of the English language :-(.

An extension of this fallacy is to say "Xs Do Y and yet they do Z" where some Xs do Y and some Xs do Z and there is some inherent contradiction between Y and Z. This is designed to highlight dishonest or incoherent behaviour, but of course glosses over the possibility that the sets of Xs doing Y and Xs doing Z have small intersection. This is especially frustrating for members of X who do Y but not Z. Example: "Yesterday Australians liked cute animals, today Australians club baby penguins, WTF?"

Sure, these examples are ridiculous but real ones are everywhere. (I don't cite real examples because their content would distract from the point.)

Update A couple of people mentioned that this is a subcategory of motte-and-bailey behaviour. Actually I really like that Slate Star Codex blog. There's an article there that is quite similar to a theme I wrote about.

Monday, 14 November 2016

Handling Hardware Lock Elision In rr

Intel's Hardware Lock Elision feature lets you annotate instructions with prefixes to indicate that they perform lock/unlock operations. The CPU then turns those into hardware memory transactions so that the instructions in the locked region are performed speculatively and only committed at the unlock. The difference between HLE and the more capable RTM transactional memory support is that HLE is supposed to be fully transparent. The prefixes are ignored on non-HLE-supporting CPUs so you can just add them to your code and things will hopefully get faster --- no CPUID checks are necessary. Unfortunately, by default, Intel's hardware performance counters count events in aborted transactions, even though they didn't really happen in terms of user-space effects. Thus when rr records a program that uses HLE, our conditional branch counter may report a value higher than the number of conditional branches that "really" executed, and this breaks rr. (FWIW we discovered this problem when Emilio was using rr to debug intermittent failures in Servo using the latest version of the Rust parking_lot crate.)

For RTM we have some short-term hacks to disable RTM usage in glibc, and the medium-term solution is to use "CPUID faulting" to trap CPUID and modify the feature bits to pretend RTM is not supported. This approach doesn't work for HLE because there is no need to check CPUID before using it.

Fortunately Intel provides an IN_TXCP flag that you can set on a hardware performance counter to indicate that it should not count events in aborted transactions. This is exactly what we need. However, for replay we need to be able to program the PMU to send an interrupt after a certain number of events have occurred, and the Linux kernel prevents us from doing that for IN_TXCP counters. Apparently that's because if you request an interrupt after a small number of events and then execute an HLE transaction that generates more than that number of events, the CPU will detect the overflow, abort the transaction, roll the counter back to its pre-transaction value, then the kernel notices there wasn't really an overflow, restarts the transaction, and you're in an infinite loop.

The solution to our dilemma is to use two counters to count conditional branches. One counter is used to generate interrupts, and it is allowed to count events in aborted transactions. Another counter uses IN_TXCP to avoid counting events in aborted transactions, and we use this counter only for measurement, never for generating interrupts. This setup works well. It means that during replay our interrupt might fire early, because the interrupt counter counted events in aborted transactions, but that's OK because we already have a mechanism to carefully step forward to the correct stopping point.

There is one more wrinkle. While testing this new approach I noticed that there are some cases where the IN_TXCP counter reports spurious events. This is obviously a nasty little bug in the hardware, or possibly the kernel. On my system you can reproduce it just by running perf stat -e r5101c4 -e r2005101c4 ls --- the second event is just the IN_TXCP version of the first event (retired conditional branches), so should always report counts less than or equal to the first event, but I get results like

 Performance counter stats for 'ls':
         1,994,374      r5101c4                                                     
         1,994,382      r2005101c4
I have a much simpler testcase than ls which I'll try to get someone at Intel to look at. For now, we're working around it in rr by using the results of the regular counter when the IN_TXCP counter's value is larger. This should work as long as an IN_TXCP overcount doesn't occur in an execution sequence that also uses HLE, and both of those are hopefully rare.

Sunday, 13 November 2016

Misinterpreting Close Contests

I often read about close rugby games decided by a margin equal to or less than the value of one penalty kick. Many reports will interpret the result as meaning the winning side was better-coached, has a knack for winning tight games, is generally better, etc. However, a gust of wind, a muscle twitch, or many other events mostly outside anyone's control could have changed the result, in which case the analysis would have been completely different. Thus, such analysis is nonsense.

The same problem afflicts analysis of close election results. If the margin of victory is very small, who actually won is not evidence of any preexisting condition, but it is often erroneously interpreted as strong evidence for the appeal of some candidate, or the effectiveness of some strategy, etc. In a close contest, "who won" will have a dramatic effect on the future but is irrelevant to explaining the past.

To avoid this cognitive bias, I wish rugby writers reporting on a close game would complete their analysis before they watch the last few minutes of the game. Likewise for people reporting on elections.

Friday, 11 November 2016

Welcoming Richard Dawkins

Richard Dawkins wants New Zealand to invite Trump/Brexit-refugee scientists to move here to create "the Athens of the modern world".

I appreciate the compliment he pays my country (though, to be honest, I don't know why he singled us out). I would be delighted to see that vision happen, but in reality it's not going to. Every US election the rhetoric ratchets up and people promise to move here, but very very few of them follow through. Even Dawkins acknowledges it's a pipe-dream. This particular dream is inconceivable because "the Athens of the modern world" would need a gigantic amount of steady government funding for research, and that's not going to happen here.

To be honest it's a little bit frustrating to keep hearing people talk about moving to New Zealand without following through ... it feels like being treated more as a rhetorical device than a real place and people. That said, I personally would be delighted to welcome any science/technology people who really want to move here, and New Zealand's immigration system makes that relatively easy. I'd be especially delighted for Richard Dawkins to follow his own lead.

Wednesday, 9 November 2016

Dangerous Permissions

I know that "man's anger does not produce the righteousness that God desires". But I also know from Jesus' example that there is such a thing as valid, righteous anger. The danger is that when I feel a desire to be unreasonably angry, which is fairly often, I try to find a way to classify it as "righteous anger" so I have permission, or even an obligation, to let that feeling flourish. Better still if some other person validates my anger, commends it, or commands it as a duty! Often the Internet is an excellent resource for finding validation for my anger.

This is especially pernicious when the permission is actually reasonable but I use it as an excuse to enjoy rage. It's easy to look at the world and feel justified anger at, say, the latest irresponsible behavior of technology vendors. But since there's little I can do about it, feeding such anger is counterproductive; it makes me an angry, grumpy, frustrated person with an inflated sense of superiority and scorn.

A completely different sort of example is racism. Some forms of racism come easily to me and I have to be constantly vigilant against them. If someone (not naming names, cough cough) or some community was telling me it's OK to be racist (explicitly or implicitly), my job would be that much harder. Although there isn't any sort of "righteous racism", there are justified complaints about aspects of specific cultures that can be used as a cover for racist feelings. To dodge this problem, many communities try to exterminate the permission by treating any criticism of culture (or at least certain cultures) as de facto racist; this goes too far. I just try to avoid thinking about these issues unless it's really necessary, which it seldom is, and when I do think about them I have to be very very careful.

I think everyone needs to learn to identify those moments when we're seeking permission to indulge a sinful desire, and understand that even valid grounds for that permission does not validate the desire.