Posted by kevin
in Software
at
07:06 |
Monday, October 29. 2007
[display_podcast]
Since my last article about keeping software safe and bug free, I came across an interesting news flash that frightens me... Let me explain.
Apple has taken over the mp3 player market by storm. No one can come close to penetrating the market the way Apple has. I've avoided buying an iPod for over 2 years and even waited anxiously for a slim version of the Creative Vision M. Creative has the technology to compete with Apple but apparently cannot cut it on the business and marketing side. There are several posts of people getting angry (like I did) at Creative for failing to deliver a decent competitor to the iPod.
I finally caved in and joined the 'evil empire.' No, I'm not talking about the Yankees nor Microsoft. I saw the still tiny 160 GB iPod at Costco, and jumped on the Apple bandwagon. I hate having to convert video. I want more supported codecs. I hate being married to iTunes (3rd party software isn't working with the new firmware just yet). But oh man... 160 GB! I'm at 45GB of usage so far and still have lots of junk to copy over. I rationalized the decision by telling myself I can just put stuff on and never have to take it off... since it's 160 GB!
But wait... what's this?!?! " iPod Sets Man's Pants Aflame "
Okay, now I need to worry about catching on fire? What's the deal Apple? I've noticed nearly every time I use iTunes (yuck) to drop new stuff on my iPod, a new firmware update is available for download. That tells me one thing: Apple is pushing out their products before adequately testing. Maybe Creative is still testing...? Hmm...
If you are a software or hardware professional, please insist on proper design, development, and testing procedures! Let's prevent embarrassing and life threatening bugs.
Futexes are a synchronization primitive that is new to the 2.6 Linux kernel. If you're like me and had never heard of them before a few days ago, then I recommend reading Ulrich Drepper's article, Futexes are Tricky. To a Windows programmer like myself, futexes are a wonderful idea that would be lots of fun to play with. Essentially, they're the antithesis of Window's synchronization model.
Hmmm. I guess I'm showing how much I dislike Window's synchronization model...
Let's start there. In Windows, if you want to use a synchronization object, you go to the Micrsoft-approved zoo of Win32/.NET synchronization objects, and you find one that's close to what you need. You then modify your problem to fit this synchronization object.
Okay, the zoo of synchronization objects that Microsoft gives you isn't bad. There are some extremely useful ones in there. If you're using .NET, you even get to use a monitor, which was missing from Win32.
In fact, if you're doing relatively normal programming in Windows, you'll never even realize that you're missing futexes. However, if you're trying to build an application that has to have optimal performance, then you may want something unusual.
You may want to do a WaitForMultipleObjects on 65 mutexes. You may want to optimize a mutex implementation as much as possible, and you're willing to give up features like re-entrance. There are a lot of things you might need, and Microsoft deliberately doesn't give you all of them. Thomas Becker has tried to implement something that's not in Microsoft's zoo, and the difficulties that he ran into are instructive.
POSIX doesn't have a universal solution, either. However, it does have a monitor, and, assuming performance isn't an issue, you can solve any problem using this.
Futexes are all that and more. They let a programmer write their own synchronization object in user mode. They do this by avoiding doing anything that's unnecessary. A futex lets you have a thread join a wait list and sleep until it is woken. The user mode code decides when a thread will enter the wait list, and when threads in the wait list will get woken up. They're still a bit new, and they don't let you control which thread gets woken up with much precision. Even if it's missing some features, however, it's still an exciting idea. It allows user mode libraries almost complete control over the performance and features of a synchronization object.
That's pretty darn clever. My next goal is to find an application at PC-Doctor that needs a futex. It sounds like a lot of fun, but it won't work on Windows.
This morning was PC-Doctor's 14 th anniversary! To celebrate, the management team at PC-Doctor put in overtime and bought a lot of goodies to give away to employees.
Wow. That's pretty cool.
Maybe I'll win a 50" TV or some Raiders tickets or the massage chair.
The management team picks names, ostensibly at random, and when someone's name comes up, they run over to a pile of stuff they choose and claim it. Sounds great! I don't own a TV, and they've got a bunch of them here. Maybe I can get one?
It's Andy's turn! I work a lot with Andy, but his kids were sick today, so I got to pick for him. He sounded pretty happy about his plasma TV on the phone.
There aren't many choices left, but there are still a few good options remaining.
When's it going to be my turn?
Okay, now it's really hard to find anything left. What's still around?
Uh, oh. It turns out that I'm the last person.
What's still there?
Woot! I get a Lady of Guadalupe Casket! Rob says that it'll get delivered next week.
While I'm not a coffin expert, it's at least got a long list of features. It's pretty long, too, so my legs would only be slightly bent!
I'd told my wife that I might win a TV. Somehow, I'd forgotten to mention that I might win a casket. In retrospect, this seems like poor planning on my part.
One question remains: Is there enough space in my cubical for my new coffin?
Posted by Aki
in Software
at
07:14 |
Monday, October 15. 2007
At PC-Doctor we've been busy with some hardware projects for some time now, and so we experienced the daily excitement that only Hardware Description Languages like Verilog can provide.
Working with Verilog provides a virtually endless stream of insights to someone who has mostly focused on software in the past. Where else is the parallelism of hardware execution so glaringly exposed and laid bare for unsuspecting programmers to trip up on?
For instance, I can, by omitting a single �<� character, change a previously happily humming expansion board to one that likes to eat motherboards for breakfast. Trust me, it's not a pretty sight when a motherboard starts popping capacitors in response to a bug in the firmware that was missed by the simulation test bench.
Some might say that VHDL is also an HDL and provides its users with the same capability for creating excitement, but I disagree. The formal definitions and verbose expression of VHDL hides the raw nature of the work. Reading VHDL gives me the same sort of creepies as ADA would to any honest C programmer (ADA, as in the programming language, not the disabilities act, diabetes association or dental association). It's possible to get in big trouble with VHDL, too, but it takes a lot more typing on the keyboard, just like it takes a lot of trying in ADA to cause the damage that a single careless pointer reference will do in C.
In case you didn't know, Verilog began its life as a language for simulating and modeling hardware designs. It was developed by Automated Integrated Design Systems in the early 80's. The company soon renamed itself to Gateway Design Automation, perhaps due to an obvious conflict with the initials of the company name. Gateway was later acquired by Cadence, who made Verilog an open standard in the mid 90's.
The cool part about Verilog is that it was intended to model and simulate hardware. This means that it makes twiddling bits and defining hardware features incredibly easy. Sort of what C did for software when it was introduced.
A major difference between software and hardware design is the difficulty of validating a hardware design. While a good software design always includes an associated test suite, it's possible to design quite extensive software projects based on manual execution and �debugging on error�. Needless to say, this is not a wise approach for hardware designs that can experience a wide range of problems, including self-destruction in the right circumstances.
A particular aspect of modern hardware design is the clocking that's used to synchronize events within the design. Clocks are forced on hardware designers due to difficulties in reliably predicting the switching characteristics of gates, transmission lines, etc., that make up an integrated circuit. Rather than trying to figure out switching times for every possible gate transition, and adding circuitry to make sure that outputs only change from one final state to the next, it's far easier to agree on a time limit within which every part of a design will respond to a change in the state of inputs, and allow outputs to toggle as they may in-between.
This is where the infamous @ (posedge clock) steps in. It is the command that forces a wait until the next positive edge of the agreed-upon synchronization method, the clock signal. A design without at least one instance of that magic phrase will often mean bad things for the implementation of the design. (Volumes have been published on this topic; just search for �Verilog� and you'll get more details if you want them.)
I used to not like the idea of the clock. Hardware switching is incredibly fast, yet clock synchronization forces an effectual wait-state on all but the very slowest logic-sequence. Why would I want to give up significant processing bandwidth to a synchronization scheme?
I was not alone in being unhappy about clocks. Just read http://www.eetimes.com/in_focus/embedded_systems/OEG20030606S0034 and http://www.eetimes.com/story/OEG20011025S0074.
To add to the allure of clock-less design, it is not difficult to write such designs in Verilog, requiring merely a switch to event-based flow instead of clock synchronization. Simulating clock-less designs is no different than simulating clocked ones.
Unfortunately the implementation on actual hardware is a can of worms. The designs that we create are implemented on CPLD and FPGA parts. These are essentially collections of logic gates with interconnections. The interconnections and the logic gate functions are programmable, which makes the whole chip do what we want. What I found out is that trying to synthesize a clock-less design will eat up a significantly higher number of chip resources than a clocked one, and will in many instances have bad timing characteristics.
The problem seems to originate with the switching and signal propagation delays inherent with all electronics, and the implications this has on clock signals. In order to minimize clock �skew� to a large number of gates, CPLD and FPGA vendors implement additional propagation circuitry for clock traces, and hence designate only a relatively small number of traces as clocks. Some parts have as few as 4 of them, others 60 or more, but these are always a relatively small proportion of the available traces.
The small number of low-skew clock traces becomes a problem in a clock-less design, where an implied clock is carried from one processing block to the next. Once the number of implied clocks exceeds the number of available low-skew clock traces, the design will incur significant bloat as synthesizing and fitting tools attempt to make the limited resources do what the designer wants.
Things are made worse with the difficulty of predicting behavior across clock domains, which means that fewer of the synthesizing tools' size and performance enhancing optimizers can be applied.
Perhaps things would be different if we were working on ASICs that allow the designer more freedom in stating what takes place where. Things would also be different if FPGA vendors were to introduce additional �local� or �mini� clocks, that could be used to implement a large number of implied clock domains.
But since we don't work on ASICs, and the FPGAs we work with don't have cool clock domain features, we are stuck with the clock. We just better love it, because hating it won't change a thing.
Posted by Aki
in Hardware
at
09:33 |
Thursday, October 11. 2007
[display_podcast]
I just read about yet another Lithium ion battery spewing flames ( http://www.wsbtv.com/news/14271878/detail.html). This one was from an iPod Nano, but it would be unfair to claim that it happened because it's an iPod. In the past we've all likely seen or heard of the Dell laptop that caught fire in Japan, and the ur-event itself, the first portable Mac that did the same. And how could one have missed the massive Li-ion battery recall of just a year ago, which affected pretty much every brand of laptop in the market. The latest is the Nokia recall of Li-ion batteries, specifically the BL-5C. See http://batteryreplacement.nokia.com.
The problem with Li-ion batteries is their ability to self-ignite under certain conditions. This is best described in an article all by itself, and here are two good links for it: http://computer.howstuffworks.com/dell-battery-fire.htm and http://en.wikipedia.org/wiki/Lithium_ion_battery.
Now it's obvious that there are many safeguards built into Li-ion batteries, and considering their massive use in most portable electronic devices, the number of failures is very small. But what's next?
I usually don't like to ring the caution bell, but the potential for trouble from Li-ion is significant. Had the Dell laptop fire occurred on-board an aircraft, instead of inside a meeting hall, it would have posed a whole new set of challenges. No, I don't believe a plane would catch fire or crash, but it would be a very unpleasant experience for many.
What I'm worried about is the aggregation of more Li-ion batteries to achieve with battery power what used to be done using other forms of energy storage. Mainly I'm thinking of electric cars, but this concern is not limited to the application itself.
On the upside, electric car batteries can employ additional safeguards that are difficult to implement in size- and weight-limited portable electronics applications. However, while portable electronics can expect the occasional drop, they don't have to undergo a 60-to-0 transition with significant plastic deformation of the containing frame (fancy words for a high speed crash).
I don't believe the question as to what happens to lithium ion batteries when they are violently deformed and short-circuited has been explained with sufficient clarity. Wishing or by calculation determining that there is no issue is akin to the thought process that left the Ford Pinto fuel tank the way it was.
Then again, if we were all worried about trying new things out, I would have taken a horse buggy to work today, and I'd be writing this out by hand, dipping my pen into a container of ink to recharge it every now and then.
Perhaps the middle ground is to be aware of the issue and look for better alternatives. Not too long ago I had an interesting conversation about the new breed of super capacitors coming out. The applications are endless, such as notebook battery recharges in seconds, but the repercussions of short circuiting one of those can be even more spectacular than with Li-ion. But that's a bit too far out for us to worry about for right now. Suffice to say that it's the consumers who decide what they buy or don't buy. Sadly, the car industry figured out the hard way that safety does not sell. Will it be the same for electronics?
Posted by Doug V
in Grab Bag
at
08:49 |
Monday, October 8. 2007
[display_podcast]
The next time you think about viewing a video on YouTube, think again. According to a news story that aired this morning on NPR, hackers are delivering spam, stealing data and introducing computer viruses via online media players.
http://www.npr.org/templates/story/story.php?storyId=15091693
The story quotes a technical spokesman from IBM Internet Security Systems, a new division recently acquired by IBM, which has shipped systems with PC-Doctor software since 1997. Here is a link to find out more about IBM ISS and its security information.
http://www.iss.net/
When you localize a product into a right to left language such as Hebrew or Arabic, how much do you have to change the position of UI elements?
It's a pretty simple question, and I think the answer is also pretty simple. If you have to have your eye on the right side of the page to start reading a sentence, then your eye is going to start on the right side of the page.
As far as I can tell, that's the extent of the problem. What are the implications?
You can't assume that users will start in the upper left corner and scan down to the bottom right of a page. Important navigation tools should be on the right or the top. Tab order should go from the right to left.
Is that the whole story? As someone who knows absolutely nothing about the subject, it's tempting to say yes. Unfortunately, Saleh, a Persian blogger, knows better. I recommend reading his blog
Windows Vista has given up fairness in their synchronization objects. In fact, Windows XP isn't guaranteed to be fair, but Vista goes quite a bit further.
The issue and the solution is explained pretty well by Joe Duffy over here. At first glance, it looks as though this could cause some really bad thread starvation in some circumstances.
The change to unfair locks clearly has the risk of leading to starvation. But, statistically speaking, timing in concurrent systems tends to be so volatile that each thread will eventually get its turn to run, probabilistically speaking. Many more programs would suffer from the convoy problems resulting from fair locks than would notice starvation happening in production systems as a result of unfair locks.
The problem they're trying to solve and the problem that I'm worried about are pretty similar, so it's worth explaining it carefully. If you have a mutex that protects a small chunk of code, and you have a large number of threads trying to get that mutex, then you have the potential to have a lock convoy. You can get this easily if you wake up a large number of threads with the same priority and have them all immediately try to get another lock.
Here's what happens. A bunch of threads are waiting for a mutex. A thread releases the mutex. Under Windows XP, the next thread in line to get the mutex now owns the mutex and gets a temporary priority boost. Windows does a context switch to the new thread, and it performs a short operation and releases the mutex. (Note that this will also boost the priority of the next thread in line, but that thread will have the same priority, so no context switch is performed.)
These context switches are expensive. Joe Duffy claims that it's about 1000 cycles. Avoiding these switches would be a good thing, so Vista changes the way mutexes work. When a thread releases a mutex under Vista, the mutex does not become owned by the next thread in the queue. Instead, it becomes unowned. This allows a third thread that's already in the running state to grab the mutex and keep going without any context switches at all. That's much cheaper, much less fair, and has the potential to starve the waiting threads.
One problem with this is that you're giving priority to running threads over waiting threads. As the number of cores in your CPU goes up, then the number of running threads gets higher. Eventually, isn't there going to be some starvation of the waiting threads?
I tried for a while to construct an artificial scenario where a thread could be starved for a long period of time. I've got to admit that I couldn't do it. The reason is that there is always some randomness in the scheduling. In order to make it so that there is a problem, I had to increase the fraction of time that a thread holds the synchronization object. Once you do that, you're going to limit the number of threads that can run without having to run into problems with a lack of fairness. It feels as though that might be true of all problems where this change becomes bad, but I couldn't prove it.
In short, Vista gives up the pretense of fairness in synchronization objects, and it does so without guaranteeing that it doesn't starve a thread. However, it looks to me as though thread starvation will never be a huge issue.
Posted by Doug V
in Software
at
10:02 |
Tuesday, October 2. 2007
[display_podcast]
I tried. I really did. I wanted it to work out between us. But it didn�t.
After one quarter of damnable blue screens, unexplainable freezes and uncountable reboots, I abandoned Windows Vista and upgraded to Windows XP.
That�s right: It�s an upgrade.
Why? XP works and Vista did not. It�s that simple.
I don�t care that Vista works fine for some.
I don�t care that Vista has a few cool features that I would like to use. Cool features don�t mean a whit when the OS frequently flakes.
I do care about productivity. And I care that I�ve lost many, many hours because of Vista.
It�s been two weeks with XP, and guess what? Not a single reboot or freeze or blue screen. Wouldn�t you call that an upgrade?
|