Browsed by
Author: admin

Your lockless future!

Your lockless future!

Queue grainy PSA video: “Here at the Intel Bit labs, we’re working on some exciting new things…”

Sufficed to say, multi-core programming is getting bigger and bigger – and is here to stay for the foreseeable future. We started back in the day with a single monolithic compute engine that people queued up jobs for. In the 60’s and 70’s, those big monolithic servers got many cores/threads – but you still queued up your individual jobs to run on them. Then, in the 80’s – single core computers caught on. Now, in the 2000’s, we bring many cores to the desktop masses. Now nVidia and ATI have graphics cards with hundreds of programmable ‘stream’ processors with massive floating point math support (dot products, 4×4 matrix multiplication, etc). And I’ll wager this is likely to be the direction for the next 10+ years. Gone are the halcyonic days of yore when one could write monolithic code for a single processor. And with multiple cores, comes multiple new challenges.

The first is algorithms and data structures. I just finished writing my first lock-less, thread-safe data structure. Granted, it was a simple lockless stack, but lockless and thread-safe none-the-less and was used to feed jobs to several cores. Seeing it in action is quite impressive. I had multiple producer threads filling it, while multiple consumer threads tried to empty it. Consumer/producer threads could switch back and forth being producers if the job queue emptied out too fast, or switch over and become a consumer if the stack was filling up too fast. All without loss of a single data element, and all without a single semaphore.

If you’re a computer programmer, you owe it to yourself to start thinking and writing in a thread-safe manners from here on out – and learning when you can ply your trade – and where you can’t. I know in my time, parallel algorithms were kind of a ho-hum addition towards the end of your algorithms courses. The 90’s was when all the big super-computer companies were going belly up. A lot of the research had already been done, and the basic take-away was that for some operations, parallel algorithms scale by the number of cores nicely, others stubbornly don’t scale at all. Best crack that old book and get yourself familiar with which ones do/don’t again.

There are two ways to go about thread safety – using the inherent structures of an API/system (SQL or other systems that inherently are built to handle multiple requests in a threadsafe way), or using hardware intrinsics down at the core. You should learn them both. Knowledge of high-level system abstractions is good, but when you find that suddenly your getting the same element twice, or one dissappears, or you get garbage at random intervals – you need to know how it works underneath – in spades.

Debugging parallel algorithms and data structures can be very painful. A very brilliant guy here worked for several weeks on a lock-based queue with memory/node reuse. The bugs were tenacious and very hard to duplicate. Some took a week or better to show up. The simplest change would fix or completely destroy the system. Memory allocation was something of voodoo art (anyone want to become way famous by writing up memory allocation routines for parallel/lock-less algorithms??). You think malloc/free bugs were hard to find before…

At least familiarize yourself with these topics:

  • New atomic hardware instructions – atomic increment/decrement, compare-and-swap, etc.  There are new commands coming out with each new processor – go find out what they are.
  • What new services are provided by my OS/language for synchronization?  I actually have had to use inline assembly for new hw intrinsics because many compilers don’t expose the new commands just yet but certain lock-less data structures and algorithms can’t be written without them.
  • What API’s/OS calls are thread safe at the app level, the thread level, and/or the os level?
  • Learn how to debug a multi-threaded app
  • What algorithms (searching, sorting, counting, etc) parallelize nicely, which do not
  • What kinds of data structures can be lockless? Which can’t?
  • In what novel ways can I combine lower-level atomic operations to build new atomic instructions (such as using atomic INC and CAS to build an n-way CAS)
  • How do I handle allocation/deallocation in a multi-threaded app?

Got more?

April fools

April fools

How’s this for fun. I went in this morning to sign the auto loan for my car. I then arrived at work and told everyone I bought a car. They laughed, and said, “Yeah right – April fools isn’t it?”. But no, I really did buy a car “yeah really – show us”…but I can’t…it’s in Indiana right now…but it’ll be here in a couple weeks… “Oh yeah – suuurrrreeee you did…”

Doh. Nobody believes me. 🙂

Finally

Finally

I finally bought my ‘new’ used car today. It’s back in Indiana at the moment, so it’s getting shipped out this way. Funny enough, it was still considerably cheaper to buy it in Indiana and have it shipped than it was to keep digging around the used market out here in Oregon and Washington. I had a terrible time finding what I wanted out this way – the used market for these cars is pretty small – and the ones I found were pretty run-out. Overall, I saved about $2000 by doing it this way based on craigslist/dealer postings – even after the hefty $700 shipping fee. Was a little tricky getting around sales tax in Indiana (they tightened the reigns); but a few calls to the state department of revenue found the answer. So, it’s a pretty much loaded 2004 Mazda 6 and comes with a 2 year/60k warranty. Here are some pictures of my new friend:

w2189_005.jpg w2189_012.jpg w2189_014.jpg

All factory: moonroof, black leather, v6 (wanted the 4, but oh well), dark grey exterior, bose sound.

It should be arriving towards the end of April.

Vista waking randomly? Try ehSched…

Vista waking randomly? Try ehSched…

This was the LAMEST thing I’ve run into as of yet in Vista. I installed Vista Ultimate on my new E6850 proc + DP35DP motherboard and for the most part it was running as flawlessly as on the E6600 with the 965OT motherboard I had previously (simply swapped mb+proc). The thing I loved most was sleep mode. Sleep in vista rocks when your devices support it – which mine do.  I can sleep and wake from S3 sleep mode for weeks without a reboot. I loved it. But on the new motherboard/proc I was having a colossally annoying problem. Every day around 10am, my machine would turn on by itself from sleep mode. I’d put the machine to sleep at night, then while I was at work it would wake up and I’d come home to it sitting there on. Wasting power is one thing, but if I left my outlook open, it would automatically download my email and gmail would move new messages so I wouldn’t get notifications of new mail at work. Annoying. But what came next was even more annoying.

I file a help request on the Microsoft tech help site and he gave me some good advice on trying to find out what service was starting my machine. I updated the bios, made sure there were no power-on-lan events going in bios/net driver, etc. The event logs list tons of startup events every time the power comes on. Lan drivers get IP addresses, sound cards initialize, about a dozen services kick off – there was almost no way to know what started the chain of events since they would start in different orders each time. You can normally see what turned your machine on by using:

powercfg -lastwake

but when I ran it – it listed NO EVENT as having woke the machine. Nada – zip. It just magically was awake. If I used my mouse/keyboard, it would list that.  So, I tried using

taskschd.msc

And finding all events running at 10am, but you know what – there is NO way to list events by time – you must dig through all the dialogs for each service to find the start times for each event. And then you have the joy of events that run “Every X hours from first run”, or “Runs when event X happens” – so you have little idea when they’ll run next (outside of looking up in the log when they ran last, etc). It was a royal pain.

I finally found some guys here that were having similar trouble and traced it back to Windows Media player and having a TV tuner card installed (which I have one). It turns out the ehSched service will run to get the latest tv channel listings if you set that up in windows media player. Well, the service doesn’t say when it runs – and the event to trigger isn’t listed anywhere I could find it.  My guess is since it’s a service, not a scheduled task. Some folks had this think kicking their PC on at 3am and waking them up. There was no way in Media center of turning off the auto tv program guide getter after you turned in on.  That was annoying – so I figured some registery hacking was in order.  Turns out – it uses a complex formula that must be decyphered to get the wake/service run time. I JOKE YOU NOT. Look at this thing:

Media Center stores the last time the download ran and the next time it will run in the registry.
The 2 entries in the registry that contain these values are respectively:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionMedia CenterServiceEPGdlLastTime
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionMedia CenterServiceEPGdlRegTime

The value is dllasttime is a6 4f 6c b6 70 dd c4 01, so enter 1c4dd70b66c4fa6 into the calculator. Click decimal and you will get 127470165639843750. At the command prompt run w32tm /ntte 127470165639843750 and you will get:

C:Documents and SettingsUserName>w32tm /ntte 127470165639843
147534 21:56:03.9843750 – 12/8/2004 14:56:03 (local time)

NUTS! Anyway, the guys on the forum wrote up a program to decypher then change the start time – but many found that it would drift after a few days and end up waking you up at 3am again. So, I went in to services.msc and disabled the service. But it didn’t work the first day.  I looked again, and thanks to the new features of vista – there are now retry events associated with your services.

So, to shut this off you must:

1. Start services.msc at the command prompt
2. Scroll down to “Windows Media Center Scheduler Service”
3. Select that service, and in the “General” tab, stop the service, and set the startup type to “disabled”
4. Then, select the “Recovery” tab, and for first, second, and subsequent failures, select “Take No Action”

Now my machine stays asleep all day. Thanks Windows Vista – for making my life easier!

Flooded cars flood the market

Flooded cars flood the market

I’ve been in the process (about 2 years) of ‘any day now I’ll get a new car’ – but have struggled to find one that I actually like. There’s too many cars I just don’t get that feeling of ‘it’s the one’ – and I’ve driven everything from Subarus, BMW’s, Lexus, to Nissan, Hondas and Mazdas. However, I’m starting to narrow my focus to some Mazda 6’s. I just happen to find one that matched a lot of what I was looking for, so I took it for a drive and had a mechanic check it out.

Well, let me just say that before I dropped it off – there were a few things that were bothering me mechanically about the car – but I decided to just let the mechanic check it out for me. Needless to say, when I got back, we discovered that it had likely been flooded. There was a water line about half-way up in the trunk. The carpet under the rear floor mats was wet underneath (had to pull up part of the carpet to feel it) but they had dried out the front carpet areas to where they weren’t wet at all – however it was obvious they had pulled the carpet up and put it back (they didn’t even snap all the molding back). They did a rotten job trying to hide the damage. They didn’t even try to dry under the back. They just threw away the trunk carpet all together.

But the shocking part was how non-visible the damage was. In the trunk, the water line was just a little coating of white pills – kind of the like little balls of white lint you get on a coat. Unfortunately, those white lint balls were really the glue that had leeched through. Try as I might, I couldn’t find any brown mud or rust on bolt heads. I looked inside frame mounts and didn’t see any other obvious water or rust marks. If they had done a better job of cleaning the car up (or putting it back together) – it would have been very hard to spot.

So, here’s some tips to look for in checking a car out for water damage:

  • They’ve tossed all the original floor mats and/or the trunk floor liner
  • Open the spare tire well – mine had little puddles of water in it because the holes that normally let the water out were plugged (probably from being submerged).
  • check under ALL the carpets – front and back. This requires taking some of the plastic floor and kick-well plastics out – but do it. My fronts were perfectly dry, but the rears were wet.
  • The front carpets clearly had ‘air bubbles’ under them. In other words, the carpet had been lifted up, then put back, but it was no longer sticking to the metal floor – so it slide around and had areas that popped up.
  • Use your nose – but it is subtle. I smelled perfumes but underneath that there was still a faint wet/musty smell. Put the windows up and blast the heat for a better effect.
  • See if the plastic molding around the door – especially the lower moldings – have recently been removed. Look for little pry marks or broken/missing plastic fasteners. The ones on this weren’t even put back all the way. Clearly they’d been mucking around down there.
  • Do a VIN check – and see if it came from a recently flooded area – but don’t trust it to say flooded. Here’s the report I got for the car from experian/carfax. You’ll note there is no mention of flood damage and it still qualified for their title protection. Renton is where I-5 flooded shut about 2 months ago.
  • Check the electrical plugs under the dash or under the car in low-hanging areas. Get the big plugs with multiple wires or thick connectors and unplug them. If it’s sat in water, the water will have seeped in and gotten stuck. They can’t have cleaned them all out. Water in the plugs = totally sat in water for some period.
  • The transmission fluid was black. Like used motor oil. This alone is enough to make one run. Check the oil for foam or discolorations too. But don’t count on it – an oil change and transmission change would have made this not visible.
  • Check the brake pads and brake assembly out. That’s raw metal. If theres lots of rust that looks unusual, the brakes squeak a lot or feel odd, odds are good it sat in water. You might even get lucky and see a water line on parts of the rotor if it hasn’t been test driven much.
  • Check for ticks or weird feel from the steering column. When turning from a start, I could feel a tick in the steering column. This might just mean bad CV joints if the mileage is high enough, or it could mean the CV joints sat in water and are starting to rust. Either way CV joints = $500.
  • Don’t trust looking for rust around bolts or mud lines. I didn’t see ANY. I looked inside frame plugs too – no dice.

My dad worked insurance for many years – and he confirmed it can be very hard to spot a flooded car if they did a good job cleaning it up. These guys did such a poor job trying to hide the damage that it was pretty obvious. If they’d changed the tranny fluid and really dried it out (front and back), and put the plastics back right – it would have been very unlikely to have been spotted. ALWAYS find a mechanic who is good to check these things out. My $80 saved me thousands. Always always always get an inspection. They cost under $100 and they usually can spot at least $100 worth of stuff that you can use to deduct from the price of the car – making the inspection almost free.

If you suspect it’s been in water – RUN, don’t walk. Don’t even both no matter how much you like the car. The mechanic said this would be the likely progression of woes from this car: you’d do the transmission oil but it would likely start failing within a year. Odds are good the electronics would start dying within 6 months – lights stop working, fuel pumps, anything electrical would die or go wonky as the wires and electronics rusted and shorted. The CV joints/axles would likely need replacing within about 6 months, and probably the calipers and brake systems too. If you’re lucky, water didn’t get into the oil pan. If unlucky – get ready for an engine rebuild. In other words – this thing would have totally self destructed.

This car was being pushed by Nissan of the Eastside in Belleview, WA. These guys had clearly seen the damage and tried to cover it up. When I got back – it was pretty clear they knew what I’d found. I told them I was going to get a thorough inspection of the thing, and they still insisted it was fine. Total sleazes from a very up-scale place. It just goes to show how awful car dealerships are – no matter how high-end they look.

Voltaire quotes

Voltaire quotes

“There are men who can think no deeper than a fact.”

“The true triumph of reason is that it enables us to get along with those who do not possess it.”

New car time? The instrument cluster story.

New car time? The instrument cluster story.

If you’ve been in the loop, you know that I’ve been ‘just about’ to get a new car for about 2 years now. I get into some test drives, kind of narrow it down, then decide I’m just as happy with the old car and don’t want to have car payments again. Yep, the 15 year old Nissan is still running strong and this year I should top the 200k mile mark. But to help myself along the process, I’ve been fixing all the little niggling problems that I would need to in order to sell my old car. One of which has been a problem I’ve had for the last two years – and this one turned out to be really cool.

The problem was that on very cold mornings (i.e. only in winter), when you turned it on, the speedometer would jump to 30-40mph – while you were still in park. If you put it in gear, it had no power and wouldn’t shift into overdrive. On REALLY cold days it would be stuck at 0mph and wouldn’t even shift out of first. You had to wait about 5 minutes for it to warm up and then it would be perfectly normal. At first I thought it was a transmission problem – so I didn’t do much with it as a rebuilt tranny would be about 1/2 the value of the car. But with a possible sale pending, I knew I needed to at least know what the problem was for full disclosure to the person buying it.

I took it to a great transmission guy I know – and he said there was nothing wrong with the transmission at all. No codes, everything is fine. Instead, he said, what was happening is when the speedometer was reading 30, the car thought it was going 30, and shifted to 3rd gear (hence no power). When it was stuck at 0, it wouldn’t shift because the car thought it was going – well – zero mph and should stay in first. He sent me to an electrical guy that reproduced the problem and found that all the speed sensors and engine sensors were working fine. It wasn’t in the sensors or wiring – it was in the actual speed cluster itself (pictures are from when I tore the heater core out – how’s that for lucky!). Huh? The actual instrument cluster was causing bad shifts? I had a hard time swallowing that at first, but he seemed sure. Problem was that a new speedometer cluster was $950 – that’s more than what it would have cost to get a rebuilt transmission put in my car. Sigh. He didn’t have a line on any used or refurbished ones because I have a really unique speedometer cluster – one that has a heads up display. Yep, my 15 year old car has a fighter-pilot era polarized glass/heads up display. I wasn’t ready to dump that kind of money – so I told him to hold on while I made a few phone calls.

I called my favorite junk yard – and they happened to have a 93 nissan altima in the lot. I had them pull the cluster and they charged me a much more reasonable $50. I took it to the mechanic guy who put it in, but it then wouldn’t read any speed, nor shift out of first. Huh. It was from an automatic car – but the junk car didn’t have a HUD. Could it make that much of a difference? The backs were almost identical – minus the HUD sending unit. I also picked up an interior light dimmer switch for $5 from the same junk car because mine seem to have a short in it and would blink the interior lights when it went wacky.

Off to the Nissan forums, posted the question/pics, and got an answer back – better than an answer actually. Answer is that in Altimas, the non-HUD clusters don’t work in HUD cars and vice-versa because the speed sending units are analog vs digital (respectively). But this guy actually has a HUD cluster he’ll sell me for $60. I buy it and go to a speedometer shop (because I was very unsatisfied with the previous shop as they left my dimmer unplugged so I had no interior/console lights when driving at night and they were very slow/a day late on the work they did) where he rolled the odometer to match the old mileage and plugged it in (I also leaned over and put the new dimmer switch in at this point and verified the old one had a short). Voila. It shifted (and the lights dimmed!), but would it solve the problem? I would need to wait for a cold morning. Note on this kind of work: I would have done it myself (20 minutes worth of work), but you need a shop that will officially vouch for the mileage or you get nailed by DMV brands your car as having invalid or odometer tampered mileage – usually knocking 1/2 its value off.

Next cold morning – 100% success! Shifting problem fixed. In fact, it shifts more cleanly in everyday driving too. Who would have thought a speed cluster would cause a shifting problem. Live and learn. Now to get out and make sure it’s up to snuff.

Here it is – we’re pink

Here it is – we’re pink

Finally – Here is the map by county with real numbers. This is what I’ve been curious about for some time

RealtyTrac has reported the numbers of mortgage foreclosures for 2007 – by county/state. It appears the Portland area is pink to red – higher than I originally expected. The rates of change are dramatic- the number of forclosures from 05-07 increased dramatically – and this year is shaping up to be even more than last. This is a problem that will only get worse before better by most experts accounts.

Even though people are supposed to be getting reprieves from the government for a month or two, most experts (and I would agree) don’t think this will help.  When the average behind mortgage owner about 5-9 months behind in payments; a month – or even 6 – probably won’t matter.  They bought too much house with too little money.  They simply must refinance to a reasonable rate, or they need to get out.  And I hate to say this, but probably most of them need to get out of homes they can’t, and never could, afford.

As someone that is saving up money for a down payment on a house, here’s what I’m thinking (to all you experts). I’m sitting on my money. And I’m going to sit on it at least a year or two. There is still way to much danger of these mortgage problems spreading and with recession on the lips of many – prices are NOT going to go up any substantial amount. There is simply NO good reason for me to pull my money off the sideline right now. You might quote that Portland area property values are holding strong – if not seeing a small 2-3% increase even last year. Interest rates are at and even LOWER low than they were during the boom. One might point on that mortgage interest is deductible and a house is a great tax shelter. Again true, but if the house you’re buying today for $300,000 is worth $250,000 next year – no amount of tax deductions will offset that.  On top of that, if it depreciates  more than 5-10%, then it’ll take me 3-5 years to recoup that lost equity.  Also, even if the average growth for last year was 2-3%, there is still a lot of properties that are overdue for an adjustment based on location and I am getting an FDIC backed 4.5% on my savings account -right now.  Finally, interest rates aren’t likely to go up any significant amount anytime soon; so there is no rush to lock in now.

On the bright side of things, houses that are priced reasonably sell very well and quickly in Portland. I’ve been watching houses come up and get sold or sit for months around my neighborhood. If you’re overpriced, you’ll be sitting there a long time. One arrogant fool started by asking 1.3 million for a condo nearby about a year ago. It’s now a year later and she/he is down to 950k and it still isn’t even close to selling. Meanwhile, in the same complex, I’ve seen 3 units sell for 350-550k in just 1-2 months. However, one thing is for sure – I’m actually seeing for sale signs. Up until about a year ago, stuff sold so fast that they didn’t even put the sign up before a bidding war was on. I had friends tell me they had to put bids on things sight unseen just to get a chance to look at the property. I taught me again that one should never buy during a boom/high demand period – that is the definition of high. Instead, buy at times like now – when people are licking their wounds, people are losing their property, etc. That’s what buy low and sell high looks like – at least in this case – and it isn’t pretty.

Anyway, here’s where Oregon is:

State rank in # of foreclosures: 22
Total # foreclosure filings: 10,746
% Change from 2006: 12.25%
% Change from 2005: 56.76%
Total proprties with filings: 8,461
% Households (foreclosure rate): 0.543%

So, that’s the story. Feedback?