The most exciting thing about this world is its ever changing quality.

Friday, February 12, 2010

Choice

I was exhausted from a long stressful week with a tough customer, although exciting but I had enough for that week, waiting for a flight to get back to my two months old baby girl. I had always tried to get to the gate in the last five minutes. Right back then, I have been waiting in the lounge for more than an hour already. How eager was I to get on that plane, you get the idea.

Then the voice came on, "I am sorry to announce that the flight from xxx to xxx is delayed, DUE TO weather condition..." Crap, that's my flight No., I guess that's the thought flying through many brains. That's what I was thinking anyway, AND weather was marvelous!

Anyhow, this is the third announcement in a row, another two hours delay. Lounge started to get noisy and less peaceful. (This is what I learnt before - when you can't think of a good excuse to cover the bad situation, telling the truth is the better choice, and the easier one.)

Now the idea that five hours of my life would be spent in this airport, I became a little nervous. After the interruption from the charming machine voice, I had to put my book away. What could be worthy enough for five hours of my time here in this place?

While I was thinking and searching, the service desk got more and more crowded. Impatient faces plus angry voice make quite a scene. Well, I could be a nosy geek sometimes so I started to watch. Apparently most of the airline folks had lost their nerves, they were being questioned, by many people, being requested with some quite wild compensation ;), being even nudged in not quite a friendly way. Well, it's Friday, and we are all in a hurry.

Just before I lost my interests and wondering whether my eyes should be cast somewhere else to capture a moment at least pay back some of my time, there was this small but firm and calm voice slip out of the crowd. Following that, I saw a girl, in her twenties and blue white airline suite, starting to pick up the panics and iron them one by one. She accepted the responsibility, (I should say that from the wearing, she was not the gal who was in charge.) made arrangements to
those reasonable requests while declined/dodged some 'interesting' ones. The one I liked the most is that she didn't make up excuses, nor did she make false promises to try to shift the shit. Of course when things went wrong people would shout, "get the manager, we want to see the man in charge, we want to 'do something interesting to him' :)". The girl reached her manager, who didn't really match my expectation, as his reply over the microphone was "there is nothing I can do, the choice is yours."

Now there looked like going to be a riot, and I mean it. A lady pointed at the calm girl, "you people are all liars. How can you take responsibility when your boss doesn't want to, even he doesn't care about his company.". The girl replied, "I do, I care about my name on the tag on my suite. Please write my name down and you can always come back to me if these arrangement went wrong. I care about my name so I won't let it happen." I was quite impressed, I have to say. This was not some kinda movie lines that she doesn't need to worry about nothing what she might have to face in the next scene as it's just all fantasy. I walked/squeezed to reach her and tapped in the shoulder. When she turned around in a hurry, I said, "thank you, you made my
misery a memorable experience."

What went on there is irrelevant to this post now. I had what I was looking for. There is a choice and you are the person who can decide to pick or to ignore. She made her choice, by standing on her feet, by not avoiding. I am not sure whether she truly believe that to be calm is the right thing to do or she just remembered her professional training. But to me, she did a wonderful job, and she certainly made her point - she cares about her name on the tag.

When we finally got on the plane, I had my hours paid.

Saturday, January 16, 2010

A pity - Google's leaving China

On my very first day back from China to UK, the same question has been dropped on me 5 times in a row, "what do you think the whole Google's pulling out of China thing?". Frankly, I didn't know what to think, perhaps its the jet lag thing or just because the trip was too hectic. Now, after couple of days, my brain has finally settled to its usual place - I don't like the taste of it!

Last news I heard on the similar thread was Google was accused (rightly) of scanning a large amount of Chinese books without authorisation. Finally, the case was settled by Google's apologies upon an alibi "inadequate communication" with the authors. 2 days later, again, on the same page, same name, Google is now taking a high stand that it will initiate "A new approach to China". Reason being that it has detected some "sophisticated attack" to 20 companies with the intent of fishing information from a group of Chinese human activists' gmail accounts. More than that, Google waved its American power stick and convince Washington that this is a non-trivial political matter.

First of all, without taking this too far, I am a huge fan of Google, of its products, its engineering philosophy, its superb marketing and productionisation abilities, most of all, the assimilated talents it has.

I don't like the taste of this though, even that I know I would probably offend someone, inc. my closest friend. But this JUST DID NOT make sense. It doesn't take a genius to read the contradicts Google has presented here. If this really is an ethic battle, Google just lost it two days ago. In what on earth position it is to do so? To pull out from an undeniable largest emerging market just because there are organised hackers who have launched 'sophisticated attack'. Come on, who are you kidding Google! Not mention many God-fathers in this generation who helped to define the networking, security are working in Google, since when did the hacking stop in any public information network?

Admittedly, there are restrictions and information censoring in today's China, and there are many. I do not believe this will disappear easily, nor do I believe it will be quickly. I was also somewhat annoyed that I can't get to my blog, facebook, even twitter accounts back in China. However, China as a developing economy entity, there are much to be improved, consolidated. Just try to remind ourselves, which developed economy entity has not gone through a phase of transition? Much to be said with regards to communism and single party government. But we are here to do business, in a real world. When you want to manage information, yeah, you do that, but in what name can you stop others to do the same? Why can we only allow Google fishing everyone's account and information everyday just to be able to pop up relevant advertisement for its own profits? Surely it doesn't really differ from politic profits essentially.

There are many speculations in terms of the real reason behind this decision. Some says Google.cn has never really performed up to expectation, regardless tens of billions of dollars has been thrown into the pot. Unfortunately, Google has officially blocked its own way to China, with all the right or wrong reasons. My financial advisor told me one thing, market has its rule, its intelligence. It takes a genius to try to understand it, not mention overpower it.

It's a pity for China, Google represents a type of culture, an idealism. I am sure many young people feel somehow lost without their spiritual leader in this technology sector. It's probably the time for a new star.

It's a shame for Google. I would have shown my respects if it decided to pull out because of its performance, instead of an excuse-searching exercise.

Tuesday, December 22, 2009

Sense of direction - what is a plan?

We love spontaneous, and the feeling of capable to do so.

We also fear clueless as life sucks if you are not in control of your own daily shit. To keep a peace of mind, we try to predict what's gonna happen and what we can do about it if you won't get morning coffee tomorrow. As most of us are incapable of seeing what is coming and have difficulties in figuring out how on earth what happened on the other side of this lonely planet could possibly affect our own well-being, what we did in the end is guess at best, the difference is how much effort being spent to conclude such speculation.

What gives us security facing unknown is the sense of direction. Ask yourself what will cause panic in your head, driving in a foreign country or broken GPS. To me, making a series inter-dependant guesses is to draw a line from where we are to, hopefully, where we want to be - a plan. We are trying to form certain level of security when there is no such things fed from outer space.

Saturday, November 28, 2009

Have your own toolchain

Toolchain provides you the capability being able to compile your code in your way to be run on your own hardware platform. For most of programmers, in majority of their career, are trying to learn to speak (code in) one or more common language, where syntax has been predefined, compilation approaches have been chosen, assembly set has been given, hardware has been decided by the boss :-).

Now, in an ideal world (I did say 'ideal'), you would design yourself an extremely powerful chip, with unlimited number of processing cores, running any instructions in nano-second.
In an ideal world, you would probably want to cook your own assembly set to be run on this powerful chip, the first one for me would be - SORTITALLOUT.
In an ideal world, you would also probably consider to write your own compiler, implementing those funky optimisation algorithms you came across only in research lab decades back in your youth.
At last, an easy one - one thing pretty much everyone else is doing nowadays - defining your own language syntax, yeah, you are right, a new language, and convince whoever you can convince to use and re-populate your civilisation.

To have all four in place, you are pretty much in control of your own life. In real world, we tend to settle with compromise. Here we tend to pick one or two of these four items and reuse some efforts other brilliant geeks have been messing with. The normal ingredients in the toolchain include:

  • An assembler - to convert your assembly instructions into 000111....1..0., the only format machine really understand.
  • A linker - to put pieces of brilliant moments together into a big 000111......1100.
  • A compiler - with which your favourite programming language into a bunch of assembly - lower level instruction set. Yes, you are right, who need another level if we have assembly defined already? Many good and bad memories prove that you might have a point there, as in the early days, we all have one weapon call assembly code.

These three are absolutely necessary for a micro-version of toolchain. Now if you have some code already, pump them bottom up, you will be talking to your machine now. However, if you intend to get serious, you will need the following:

  • A debugger - whatever interface it is (my personal view is GUI debugger suck more than they contribute). This is a whole topic by itself and I don't really know much about so I will skip it.
  • Libraries - only if you ever want to rebuild the whole new world again all by yourself, you are going to need some of proven work done by other genius just like you, some common funcationalities everyone will come across. "This idea that there is generality in the specific is of far-reaching importance. — Douglas Hofstadter, Gödel, Escher, Bach"
  • Utilities - copy, dump, whatever verb you can think of. These tools are really food for work, and thought.

Friday, November 27, 2009

All about USB

Pre-defined USB device classes provide standard USB drivers for the devices falling into these classes. Otherwise USB device vendor will provide their own.

USB Device driver = USB Host driver (Host controller/Hub/Master) OR USB gadget (Device/Slave)

Host - Linux
LDD3 - USB

Endpoint - The basic uni-direction data channel, either from Host to Device (OUT) or Device to Host (IN)
  • CONTROL - configure, retrieve device information, send commands to device, retrieve device status report. Every USB device has a control endpoint "endpoint 0", used by USB core to configure the device at insertion time.
  • INTERRUPT - endpoints transfer small amount of data at a fixed rate everytime Host asks Device for data. These endpoints are the primary transportation method for USB mice, keyboards. Also can be used by Host to send control command to Device. NOT generally for large amount of data.
  • BUILK - for large amount of data transfer. Commonly used in printers, storage, and network devices to transfer bulk packets from or to devices. Data MUST gets through without loss, but time could NOT be guaranteed.
  • ISOCHRONOUS - also for large amount of data transfer, but data loss is possible. Used in application for constant stream of data flowing such as real time data collection, audio and video streaming.
CONTROL and BULK types of Endpoints are used in asynchronous transfer. INTERRUPT and ISOCHRONOUS are periodic. In Linux, usb_host_endpoint structure describe an endpoint, which contains a usb_endpoint_descriptor.

Interface - a bundle of Endpoints, handles one type of USB logical connection, such as mouse, keyboard, audio stream. Some USB devices have multiple interfaces (for example, an USB speaker device has one interface for audio stream, one interface for keyboard for the buttons). USB device driver and USB Interface is a one-to-one mapping relation. Each USB driver controls one interface in an USB devices. So it is likely we need multiple USB drivers to control one USB hardware device. USB driver is bound to USB Interface.

Interface structure in the kernel is usb_interface. USB core passes usb_interface structure to USB driver to control.

Each USB device will have a USB major number. Every interface will be assigned a minor number by USB core via calling usb_register_dev.


Configuration - a bundle of Interfaces. A USB device can have multiple configurations to switch in between to change the state of the device. In the kernel, structure usb_host_config represents a Configuration. usb_device represents entire USB device.

Descriptors

All USB devices have a hierarchy of descriptors which describe to the host information such as what the device is, who makes it, what version of USB it supports, how many ways it can be configured, the number of endpoints and their types etc. The more common USB descriptors are
• Device Descriptors
• Configuration Descriptors
• Interface Descriptors
• Endpoint Descriptors
• String Descriptors

LDD3 - USB

Enumeration - is the process of determining what device has just been connected to the bus and what parameters it requires such as power consumption, number and type of endpoint(s), class of product etc. The host will then assign the device an address and enable a configuration allowing the device to transfer data on the bus. A fairly generic enumeration process is detailed in section 9.1.2 of the USB specification.

USB File system
The first USB device is a root hub, or known as USB controller, usually contained in a PCI device acting as a bridge between PCI bus and USB bus. It is also the first USB device on USB bus. All root hubs will be assigned unique number by USB core.

USB sysfs device naming scheme: root_hub-hub_port:config.interface
[USB Selective Suspend - The USB selective suspend feature allows the hub driver to suspend an individual port without affecting the operation of the other ports on the hub.]

Kernel will bind the correct USB driver to interfaces specified by configuration based on bConfigurationValue in a USB device.

sysfs (/sys/) stops at the interface level without exposing all parts of USB device.
Detail information of endpoints can be found in usbfs filesystem, mounted in /proc/bus/usb/. /proc/bus/usb/devices will show all configurations and endpoints in the system. It also can allow user space programs talk directly to USB devices. (Hence user space USB driver is possible to be in user space rather than kernel.)

Data transfer
Via URB
usb_alloc_urb usb_xxxxxpipe usb_submit_urb
create URB URB URB Notify
Apps ---> USB device driver ---------------> USB device driver assign URB to endpoint -------> USB core -------> USB host controller (for this USB device) <> ---------> USB device driver

Different URBs are created to be bound to different types of endpoints. After a urb has been submitted to the USB core successfully, it should never try to access any fields of the urb structure until the complete function is called.

• When the function is usb_kill_urb, the urb lifecycle is stopped. This function is usually used when the device is disconnected from the system, in the disconnect callback.
usb_unlink_urb function should be used to tell the USB core to stop an urb. This function does not wait for the urb to be fully stopped before returningto the caller.

Without URB
Synchrounous usb_bulk_msg, usb_control_msg

To write a USB driver
Same thing to other subsystem drivers really, create driver structure -> register to USB kernel subsystem (-> create char driver interface for USB devices)

USB core handles the addition and removal of USB devices within a single thread, so any slow device driver can cause the USB device detection time to slow down and become noticeable by the user.

VCP over USB
COM port redirector is a powerful concept in hardware connection limited device.

USB CDC ACM: Abstract Control Model. This access model provides a serial (COM) like interface to a USB device. Each CDC-ACM channel utilizes 3 USB end-points for end-to-end communication. Linux has a generic CDC ACM host-side implementation in the kernel module cdc_acm.ko.
USB CDC ECM: Ethernet Networking Control Model. This access model provides a standardized networking interface for handling of IP transmission over a physical interface such as USB.
USB CDC OBEX: Object Exchange
http://www.jungo.com/st/embedded_usb_cdc.html


Gadget - Linux

Instead of Host controller, we have peripheral controller taking it place in USB 'slave' device end.


Typical gadget drivers under Linux are:
• Gadget Zero
• Ethernet over USB (To support different host, there are different modes: CDC Ethernet, CDC subset, RNDIS)
• GadgetFS
• File-backed storage (implementing USB Mass storage class)
• Serial (implementing CDC ACM class)
• MIDI

Sunday, November 22, 2009

R&R

I have been my new role for almost a month now, a month within which I only spent two nights at my newly purchased house.
What is different to me is that I got to spend a lot of time with customer and had chance to really understand the source of all information. This leads me to start thinking about:

1. The amount of information lost during transmission is unbelievable significant. As a startup, we only recruit people who have been working in this field for long enough time with established records. You might think that we are lucky enough that these pros would be able to interpret, parse and transmit information more accurately and timely. However, the fact turned out that we have got some priority wrong - one particular problem customer has been waiting for over two months as it blocked their development, while our engineers have no idea and were plodding through the bug list in alpha beta order, project team in customer side has been held up. On second thought, it seems while FAEs were focus on the problem to be resolved or tons of emails to reply, or evaluate whether it is ok to nag again for the bug updates, these poor fellows have lost the big picture and ability to make judgement calls.

2. Management is all about communication is exemplified to its extreme in customer management role like this. I have one crazy principle - when I decide to go to bed at night, there will be no unprocessed emails in my inbox, even sometimes it means banging Del key 10 times in a row per second. Because the nature of the role, it seems all natural and makes sense that to keep the communication flow healthily is all is required for this role. You can try that, but my experience tells me that after a very short of time, you will notice that you are not the one in control anymore - not for schedule, not for customer project scope, lose track of what the heck is going on within your engineering department. Why? Simple, because you gave up the right to control! Managing information channel is an auditing job at its best. While it is so important as I explained in previous section, if you choose the easy way out - by managing the results of people's actions reactively, you forgot about the source. If there are some areas could be improved, practice could be less time consuming, process could be less painful and distracting, the best way is to cure the source, to get on top of the fundamental reasons behind symptoms. Real managers manage people, practice, process; mediocre ones massage information; bad managers react to situations.

3. At last, one questions bothers me mostly through half of my professional career is, have we given up the right and ability to be creative, to do something for real? There are numerous blogs and articles talking about how managers with good hands on engineering background tend to screw big time by micro-managing and mistaken the purpose of his/her role just because they got too attached to write few lines of code, carry out some tests, define some protocol etc. By doing this, they lose their focus in their own jobs. Frankly I have probably read and written too much of this to the point everytime this topic pops up, I just want to shout, WHAT THE FUCK a manager's job should be?

Simple definition for manager from my dictionary - a guy whose job is to do whatever is required to accomplish team's goal.

If you need someone to get the code done and the only possible person is you, guess what, you are going to write some code. If you happen to be an expert in some areas your team require some advice, don't be shy, that IS your job. Hard isn't it? That's the price you pay when you want to be on the spotlight.

Friday, October 30, 2009

Ten most annoying things in geek's life

1. Sticky mouse, touch pad goes wild.
2. Shortcuts stop working, especially Command-W/Alt+F4/ctrl+c, z, d.
3. There is only one USB port to your laptop.
4. No chocolate within reachable distance.
5. Only one monitor.
6. No invite for stuff like google voice, wave etc.
7. Have to use windows for some strange reason.
8. Again, have to use MS Word or Visual Studio.
9. Manager just proves himself as a dumb ass, again.
10. No game and surfing in office.

Saturday, October 24, 2009

Everything old is new

Every morning when I cycle through a large piece of stretching grass land, it always gives me a sense of peace and fresh. I know it may sounds strange but I did start to enjoy the half an hour cycle trip every morning, not so much in the afternoon...

The road is the same, come across the same vans and buses, even wave to the same bunch of cyclists and morning joggers. You may have already been bored so far. Hang on, what's different on that side of the road, a hare running straight into me!

That's what happened when I sit down in the office, open up laptop, plug in all sorts of cables and re-arrange all sorts of devices and boards, all routines. I know I am good at these routines, and I also know that I can make something happen today from here. The trick is, we all start from familiar and 'boring' stuff, and many of us are also so ambitious that not willing to go through all the 'routines', to which their talents are considered to be wasted.

To me, everything old is new. Every bit of routine gives me a perfect background scene to train my eyes and mind to pick up those different, those potentially could be significant. It is those little things here and there complete every day life. It is also these little opportunities where we can pick up new knowledge, experience. There is hardly possible for us to sit in front of your shining desk and come up with a killing product idea or impulse of restructure initiative to take the organisation forward, no, no no. Things don't work that way. I realise what I have to do is to be able have a peaceful mind, accept the reality, fully appreciate what has been happening, and pick up those little lights where gold might be found. Once that happen, you bet I am right - everything old is new. You will start to look at those familiar faces differently, you will start to hold different opinions to things around you, you will notice there are so many changes quietly going on affecting the 'old' environment. Many great ideas have been generated from most ordinary moments. If you think there is a small change could benefit a design or part of the code a lot, you should do it, do it now. Do not let it pass by, as it might be the last chance you see it and after that, you will say, "today is just another boring day, nothing exciting, really.". Really?

I love to remind myself of the importance of open mind and be realistic. There is nothing wrong with one step a time, also, it is a natural steady-state evolution of how significant changes are born. Remember, everything you believe you have mastered, it has just developed, only you have missed the change, and what is coming next if you keep ignoring it.

Friday, October 16, 2009

Incompetence

Peter's principle says, in a hierarchically structured organisation, everyone will eventually be working in their level of incompetence. The reason behind is simple - promotion as reward will encourage people who has well or out performed in their current roles to new ones where they will not be familiar nor comfortable.

Scott Adam coined Dilbert's principle, in which he explains that companies tend to systematically promote least competent employee to management - to limit the amount of damage they will be capable of doing. Sounds much more fun, huh? By intentionally, Dilbert thinks the upper layers of an organisation is of no or little relevance to the productivity, which in fact is mostly achieved by the 'blue-collar' workers.

In a world where efficiency, contribution, competence are valuable attributes we are looking for in employee, how could management have been given such a bad name?

Let's see who are the managers first. Mainly there are two groups concerned. First group consists of those who have sweat and bleed on the front line enough to impress the boss and been rewarded with a manager's hat. Most of them have or had solid hands on engineering skills and confident in their interpretation and judgement over technicality of the future problems, with which they are about to be tested on regular basis. In the second group, we have people who have been given the benefit of the doubt for their background. Unfortunately, the size of this group is surprisingly and unfortunately large.

For folks who have finally fought their ways through to manager's position, it is a strange, exciting, and unease situation to be. Suddenly it seems there are way too many technical morons around you, rather than you have to sharpen your head like a nut to get boss's attention back in your engineer days; also, you feel privileged that finally you can fix all the stupid calls your boss have made in the past because he seemed to know nothing about nothing. After a while, you realise this is a completely different game - your superior technical strength will not help you surf through the tangled political mine field; your sharpness has been considered by your peers as arrogance and difficult to communicate; you have kissed good bye to the luck of having concentrated 42 minutes on one particular problem without being distracted; you also start to realise you have no fricking clue what is going on in your boss's mind or does he have one as there is just so little quantitative measurable around here.; finally, damn it, "I have missed my morning coffee again!". Being an exceptional engineer doesn't automatically qualify you to manage. If the reason you have been given the management responsibility is entirely based on the fact you appeared to have outperform in your last role, I can tell you now, it was the wrong decision. You have now been officially pushed into a strange land, to which you may not have any real interests at all. At the bottom of your heart, you are probably screaming every morning, "fuck that, I just want to hack!".

Right, now to the bad side, for those have developed their career by avoiding risks and responsibilities as much as possible but somehow able to sneak their way through step by step. How to identify these people? Easy enough, lines they tend to use a lot is, "yes, I have done exactly same thing before". Then when you ask just a little bit more, he will starts to wave the flags to get out of the confrontation as quick as possible with line like "I don't want to hang up on the details on this for too long". I guess Dilbert is right after all, for group B, the best thing to do is to keep them in the management position, of course if your company can afford it, that way at least he will cause no direct damage to whatever it is you are trying to achieve, hopefully.

Wednesday, October 14, 2009

Manager's chessboard

There is an underline synergy between being a manager and a chess player.

At the start of a chess game, if you were to win, one thing you would need to be certain and clear with the strategy, be it a waiting-for-mistakes-from-opponent, balanced attack and defence, or strike with all price. You also need to keep a very close eye on the strategy of your opponent, if you are not familiar with his/her style already, and adapt your counter plan.

For every move, not only you have to consider the immediate effects on material loss or gain, more importantly, you have to evaluate things like position of the pieces, support for the future development of your overall plan, maybe even traps to trick your opponent, as the big picture. Every move is a decision with consequence, as a manager, you have to make yours, with all the information available to you, given that you have your eyes and ears opened to receive them - you have to be able to read well whatever is on the 8x8 square; able to see through the moves from the pieces and predict the goal of your opponent, be it a local win on points or strategic position acquisition.

You have your resources - pieces, which are pretty much the only thing is on your side to get this game over with a desirable result. To mobilise and maximise the potentials, you have to be well aware of what they are capable of - En passant, what they could become - promotion, what the killing combinations are, how to coordinate the pieces - coordination, how to create healthy dependency and protection chains, how to double check.

Again, you have to make your decision, none of them will be easy, or else you might be better off just to get out of the game and try something else. Sometimes decision demands sacrifice, compromise, exchange of materials, concentrated attack, defend and counter attack. In other situation, it means being flexible (forcing a tie), realistic (evaluating situation and selecting the most appropriate play going forward), brave, calm (facing panics after mistakes).

There will be unhappy scenes, with pieces lost, positions given up, conflict interests and plans. In real world for managers, to create and manage a positive and healthy political environment is part of the job, critical one. However, the truth is, you can't make everyone happy, you never will or should. I like in 24 season 7 Jack Bauer answers Renee how he could live with all the decisions he has made. Sometimes you have to choose between two evils. "If you’re going commando to do what you believe is right, it doesn’t mean someone isn’t going to be pissed, but it should allow you to go to sleep at night." Apparently Michael Lopp has a term for this - Subterfuge.

Responses:
1. Thanks for Jiayao's comments. Pattern analysis and retrospective thinking is how a chess player can learn from the past and become better and stronger. This is in a way very much like skill training. Learning from the past, other players, summarise and make these patterns your own versions. This gives the chessboard another dimension - as a manager, you might not succeed in every situation with every team, the important thing is, there is no bad or good experience, it's just experience and opportunity to grow from, inc. other people's lessons.