Unix serial ports have associated input and output buffers in the kernel. When writing data to the port, if sufficient space is available in the output buffer, the write call returns after copying the data into the buffer. The hardware slowly outputs data from the buffer, freeing space for more data. A program can easily fill up the buffer, because the CPU works much faster than the serial port. When insufficient space is available in the buffer, a normal blocking write will wait. It will not simply wait for sufficient space; instead, it will wait for the buffer to empty to a specific low limit.
When simply sending large amounts of data, this behaviour is appropriate and efficient. Programs don't need to constantly wake to feed more data to the hardware. Instead, they can put a lot of data into the buffer and then sleep until the buffer gets to that low limit. However, for some applications the buffer is a problem.
Bytes that are already in the buffer form a delay between when a new byte is written and when it is actually output from the port. (All those bytes need to be output first.) As a result, serial responses and actions from serially controlled hardware may be delayed. If a program performs checks to see whether to continue sending data, that will also be delayed when a write call waits for the output buffer to empty.
In Linux the output buffer is one page (typically 4KB), and the
process is woken when only 256 bytes (set via WAKEUP_CHARS) remain. That may seem like a small amount of memory, but at low baud rates, it corresponds to a long time. There is no standard way to change the buffer, and in Linux, it could only be changed by editing kernel source code and recompiling the kernel.
It is simplest to wait for data to be output after writes. This can be done by waiting for responses after writs or via tcdrain. (Other methods such as fsync and O_SYNC cannot be relied on for serial ports.) Unfortunately, this defeats the efficiency benefits of buffering.
When the issue is a need to stop output quickly, instead of a need for constant low latency, data in the buffer can be discarded via tcflush. However, this gets tricky. Since writes can wait for a long time, some form of asynchronous I/O is needed. Once the buffer is flushed, serial controlled hardware may be in an unknown state, which complicates things.
As an added benefit, tcflush and tcdrain also deal with the hardware buffer. In most built in serial ports, these buffers are tiny. However, USB to serial adapters can have large buffers.
Monday, October 24, 2011
Friday, October 14, 2011
In Linux, use the Realtek r8168 driver for RTL8168
I have a Gigabyte GA-P35-DS3R motherboard with a RTL8168 Ethernet chip.
When using the r8169 driver that's part of the Linux kernel, I often lose the connection after S3 suspend. Usually, taking the interface down and back up with ifconfig fixes it, but unloading and reloading the module is sometimes necessary. This problem has been around for a while, and it still exists in the current Linux Mint Debian Edition 3.0.0-1-amd64 kernel. Even adding r8168 to SUSPEND_MODULES doesn't help.
The best solution seems to be using the r8168 driver from Realtek instead. It solved the problems after suspend, and seems to have also sped up suspend a bit. It may have also fixed some hangs I used to get occasionally.
At first, version 8.025.00 refused to build because the src/Makefile didn't recognize that Linux 3 should be treated like Linux 2.6. I fixed this by changing the lines setting KEXT and KFLAG to:
When using the r8169 driver that's part of the Linux kernel, I often lose the connection after S3 suspend. Usually, taking the interface down and back up with ifconfig fixes it, but unloading and reloading the module is sometimes necessary. This problem has been around for a while, and it still exists in the current Linux Mint Debian Edition 3.0.0-1-amd64 kernel. Even adding r8168 to SUSPEND_MODULES doesn't help.
The best solution seems to be using the r8168 driver from Realtek instead. It solved the problems after suspend, and seems to have also sped up suspend a bit. It may have also fixed some hangs I used to get occasionally.
At first, version 8.025.00 refused to build because the src/Makefile didn't recognize that Linux 3 should be treated like Linux 2.6. I fixed this by changing the lines setting KEXT and KFLAG to:
KEXT := ko
KFLAG := 2x
After this, I had no further problems and autorun.sh correctly built and installed the driver. It renames r8169.ko to r8169.bak to deactivate that driver. After confirming that r8168 works properly, it's a good idea to blacklist r8169. It's also necessary to update the initial ramdisk, because r8169 may be loaded from there.Friday, September 23, 2011
SkyDrive: 25 GB of free storage that's too annoying to actually use
For several years, I've known that I have a Windows Live SkyDrive account with 25 GB of free storage. However, I never actually tried to use it. Today I tried to use it and I see what's the catch: it's too annoying for storing large amounts of data.
I was hoping to upload all of my photos. Theoretically, it seemed like a good idea. The photo viewer is great, the per-file size limit is not an issue, and the overall size is more than other free services allow but only a fraction of the 25 GB limit.
The first problem is that the web uploader is quite limited. It can't upload folders, so I would have to manually create them and upload their contents. It doesn't even support drag and drop, except for in IE. Since uploading would be a lot of work, I rejected this option.
Then I learned that SkyDrive can be accessed via WebDAV and mounted as a drive in Windows. (It uses proprietary Passport authentication, so I'm not sure if any other clients can access it.) This was easy once I sorted out some firewall issues. Unfortunately, only document file types can be uploaded. Attempts to upload JPEG images and archives result in an error telling me that the file "is too large for the destination file system". It's not a file size issue because it happens with small files. I guess Microsoft only wants the WebDAV access to be used for Office documents.
Since PDFs are supported, I thought about using using them. JPEG images can be included in PDFs without re-encoding, and PDFs also support attachments for other file types. However, this is a kludge without any benefits besides WebDAV access, and so I decided to try ordinary multi-part archives instead.
Archives can be uploaded via the web interface, and files of 104,857,600 bytes (100 MB, 100 * 2^20) may be uploaded. Unfortunately, this is unreliable. The Silverlight uploader only seems to allow one 100 MB file to start uploading in a batch, and even that file seems to stop before the end. The upload seems to complete successfully, because the downloaded file is bit-identical to what I uploaded. The classic form based uploader also fails before the end, and I'm not sure if it's usable for large files.
I was hoping to upload all of my photos. Theoretically, it seemed like a good idea. The photo viewer is great, the per-file size limit is not an issue, and the overall size is more than other free services allow but only a fraction of the 25 GB limit.
The first problem is that the web uploader is quite limited. It can't upload folders, so I would have to manually create them and upload their contents. It doesn't even support drag and drop, except for in IE. Since uploading would be a lot of work, I rejected this option.
Then I learned that SkyDrive can be accessed via WebDAV and mounted as a drive in Windows. (It uses proprietary Passport authentication, so I'm not sure if any other clients can access it.) This was easy once I sorted out some firewall issues. Unfortunately, only document file types can be uploaded. Attempts to upload JPEG images and archives result in an error telling me that the file "is too large for the destination file system". It's not a file size issue because it happens with small files. I guess Microsoft only wants the WebDAV access to be used for Office documents.
Since PDFs are supported, I thought about using using them. JPEG images can be included in PDFs without re-encoding, and PDFs also support attachments for other file types. However, this is a kludge without any benefits besides WebDAV access, and so I decided to try ordinary multi-part archives instead.
Archives can be uploaded via the web interface, and files of 104,857,600 bytes (100 MB, 100 * 2^20) may be uploaded. Unfortunately, this is unreliable. The Silverlight uploader only seems to allow one 100 MB file to start uploading in a batch, and even that file seems to stop before the end. The upload seems to complete successfully, because the downloaded file is bit-identical to what I uploaded. The classic form based uploader also fails before the end, and I'm not sure if it's usable for large files.
Some per-service firewall rules don't work in Windows 7
The Windows 7 Firewall with Advanced Security allows you to specify a service in addition to a process. This is important because many services run under svchost.exe. Rules which simply reference svchost.exe may be too broad.
This works well with the Windows Update and Windows Time* services. When outbound connections are disabled by default, rules can be created to permit those services. However, it doesn't always work.
In the past I spent a lot of time trying to figure out how to permit Windows Media Center schedule updates. I guess that part of the update is via the Background Intelligent Transfer Service (BITS). I said "I guess" because "netstat -b" sometimes showed them using the User Profile Service (ProfSvc), which doesn't make sense. Rules which permit outbound communication from BITS, ProfSvc, and even a large number of other services never accomplished anything. I finally gave up and created a rule permitting outbound communication on port 80 by svchost.exe (without specifying a service).
I was just trying to figure out how to allow the WebDAV client through the firewall. It obviously uses the WebClient service. In this case "netstat -b" also shows this. However rules permitting outbound communication by the WebClient service do nothing. I was forced to create a rule permitting outbound communication by svchost.exe on port 443 for SSL WebDAV access.
I'm not sure if these are bugs or intentional limitations. When creating a rule for svchost.exe, I am warned that "Windows services have been restricted with rules that allow expected behavior only. Rules that specify host processes, such as svchost.exe, might not work as expected because they can conflict with Windows service-hardening rules." Maybe Microsoft chose to not permit rules involving BITS and WebClient because they are general purpose communication services which could also be used for malicious purposes. However, it doesn't make sense that a rule specifying svchost.exe and a particular port is allowed, but when the rule is further narrowed by specifying a service, it is ignored.
* If Windows Time Service is not allowed Internet access, the first "Update now" attempt will fail with a timeout. However subsequent attempts may appear to succeed, and the time when the clock was synchronized will be updated.
This works well with the Windows Update and Windows Time* services. When outbound connections are disabled by default, rules can be created to permit those services. However, it doesn't always work.
In the past I spent a lot of time trying to figure out how to permit Windows Media Center schedule updates. I guess that part of the update is via the Background Intelligent Transfer Service (BITS). I said "I guess" because "netstat -b" sometimes showed them using the User Profile Service (ProfSvc), which doesn't make sense. Rules which permit outbound communication from BITS, ProfSvc, and even a large number of other services never accomplished anything. I finally gave up and created a rule permitting outbound communication on port 80 by svchost.exe (without specifying a service).
I was just trying to figure out how to allow the WebDAV client through the firewall. It obviously uses the WebClient service. In this case "netstat -b" also shows this. However rules permitting outbound communication by the WebClient service do nothing. I was forced to create a rule permitting outbound communication by svchost.exe on port 443 for SSL WebDAV access.
I'm not sure if these are bugs or intentional limitations. When creating a rule for svchost.exe, I am warned that "Windows services have been restricted with rules that allow expected behavior only. Rules that specify host processes, such as svchost.exe, might not work as expected because they can conflict with Windows service-hardening rules." Maybe Microsoft chose to not permit rules involving BITS and WebClient because they are general purpose communication services which could also be used for malicious purposes. However, it doesn't make sense that a rule specifying svchost.exe and a particular port is allowed, but when the rule is further narrowed by specifying a service, it is ignored.
* If Windows Time Service is not allowed Internet access, the first "Update now" attempt will fail with a timeout. However subsequent attempts may appear to succeed, and the time when the clock was synchronized will be updated.
Thursday, September 22, 2011
Brown polarized sunglasses are great!
I used to wonder why someone would want brown or amber sunglasses. Why add a colour cast to everything? Now I know. The colour:
Polarization is also an important enhancement. It:
When buying polarized sunglasses, it's important to check whether the effect works well. Turn the glasses and block some reflections. Cheap glasses may not be able to block reflections very much, or the blocked reflections may show a strong purple colour cast.
- decreases sky brightness, equalizing the overall brightness of the scene
- removes glare, while still making the scene appear bright in a pleasant way
- accentuates green foliage and various other colours
- makes hazy days seem sunnier
- helps decrease glare when driving toward the sun
Polarization is also an important enhancement. It:
- decreases the intensity of annoying bright reflections from non-metallic surfaces, such as reflections from the paint of cars or bodies of water
- increases colour saturation by removing reflections (Foliage reflects a lot of light, and looks much greener when that reflection is blocked. Water surfaces also reflect light, and when that reflection is blocked, the colours of the water itself stand out.)
- makes the sky darker and bluer in certain directions, making clouds stand out and helping equalize the overall brightness of the scene
When buying polarized sunglasses, it's important to check whether the effect works well. Turn the glasses and block some reflections. Cheap glasses may not be able to block reflections very much, or the blocked reflections may show a strong purple colour cast.
Monday, August 29, 2011
Stores selling cheap stuff from China
There are many online stores which sell a wide variety of cheap stuff from China, usually with free shipping. The prices can be impressively low, but the quality is sometimes questionable.
DealExtreme seems to be the most popular one. So far, I've ordered several items from there, and overall I've had a good experience. I'm using the 10W 500-Lumen Multi-Color RGB LED Emitter Metal Plate (140 degree) in my RGB lamp, and I'm happy with it. Their 5mm white LEDs are also good, with a nice colour and good brightness. I also got a nice 55mm lens cap.
So far, I've only had one problem with DealExtreme, and that was resolved in a good way. I ordered what was at the time advertised as a Massa circular polarizer for my camera. The packaging and item I received made no mention of Massa, and the item looked different. When I contacted DealExtreme, I got some store credit. The polarizer does provide decent photos as long as I don't zoom much, and I really like some photos I took using it. I also see that DealExtreme updated the item description and photos, showing what I got. As a result of all of this, I'm satisfied.
My favourite thing about DealExtreme is the reviews and forum posts. They seem genuine, and they provide useful information about the products. Yes, DealExtreme does sell some bad products, but the reviews and other information make it possible to avoid most of these.
The only real complaint I have is that some simple actions (such as redeeming store credit or DX points) require customer service interactions. These things would be easier and faster if automated. However, customer service always responded promptly, so this is not a major issue.
The main thing that motivated me to write this post is my first purchase from DinoDirect and what I saw when I spent more time on that site. It's a big contrast; DealExtreme is much better. For example, check out what other people have to say about DinoDirect, and look at the quality of item reviews on DinoDirect.
DealExtreme seems to be the most popular one. So far, I've ordered several items from there, and overall I've had a good experience. I'm using the 10W 500-Lumen Multi-Color RGB LED Emitter Metal Plate (140 degree) in my RGB lamp, and I'm happy with it. Their 5mm white LEDs are also good, with a nice colour and good brightness. I also got a nice 55mm lens cap.
So far, I've only had one problem with DealExtreme, and that was resolved in a good way. I ordered what was at the time advertised as a Massa circular polarizer for my camera. The packaging and item I received made no mention of Massa, and the item looked different. When I contacted DealExtreme, I got some store credit. The polarizer does provide decent photos as long as I don't zoom much, and I really like some photos I took using it. I also see that DealExtreme updated the item description and photos, showing what I got. As a result of all of this, I'm satisfied.
My favourite thing about DealExtreme is the reviews and forum posts. They seem genuine, and they provide useful information about the products. Yes, DealExtreme does sell some bad products, but the reviews and other information make it possible to avoid most of these.
The only real complaint I have is that some simple actions (such as redeeming store credit or DX points) require customer service interactions. These things would be easier and faster if automated. However, customer service always responded promptly, so this is not a major issue.
The main thing that motivated me to write this post is my first purchase from DinoDirect and what I saw when I spent more time on that site. It's a big contrast; DealExtreme is much better. For example, check out what other people have to say about DinoDirect, and look at the quality of item reviews on DinoDirect.
Monday, August 15, 2011
I'm still using Adobe Reader
Despite the bloat and all the people who hate it, I'm still using Adobe Reader to view PDFs in Windows. Recently, it was slow on one huge PDF on my laptop, so I decided to try out some alternatives.
Sumatra PDF was pretty good and a bit faster, but zooming wasn't as user-friendly. I didn't like Foxit Reader's user interface. It seemed like an old badly designed Linux application. PDF-XChange Viewer was pretty good, but it also had an inferior zooming user interface. The biggest problem was that all three had slow search in large PDFs, without acceleration via saved indexes like Adobe's Fast Find.
It would have been nice to switch to something leaner, but it's not really a problem. I found that disabling 2D graphics acceleration in Adobe Reader resolves the performance issues on my laptop.
Sumatra PDF was pretty good and a bit faster, but zooming wasn't as user-friendly. I didn't like Foxit Reader's user interface. It seemed like an old badly designed Linux application. PDF-XChange Viewer was pretty good, but it also had an inferior zooming user interface. The biggest problem was that all three had slow search in large PDFs, without acceleration via saved indexes like Adobe's Fast Find.
It would have been nice to switch to something leaner, but it's not really a problem. I found that disabling 2D graphics acceleration in Adobe Reader resolves the performance issues on my laptop.
Sunday, August 14, 2011
Bad capacitors and ESR testing
I have an old Soltek SL-65KVB motherboard. It was taken out of service due to AGP graphics instability which was probably due to bad capacitors. This diagnosis seemed pretty obvious because capacitors right by the AGP slot were bulging, but I didn't bother fixing the motherboard because it was a good time for an upgrade.
Now I would like to repair the motherboard, mainly because the combination of a Pentium 3, 640MB of RAM and an ISA slot could provide a nice way to use old hardware. By now, even more capacitors are obviously bad. However, only the GSC 1000µF and 1500µF 6.3V capacitors with gold/brown lettering have obvious problems and more numerous smaller GSC capacitors with silver/white lettering seem fine.
I didn't feel like unnecessarily replacing the smaller capacitors, so I quickly built a very simple capacitor ESR tester. The basic idea is the same as various other ESR measuring devices documented online: a stepdown transformer outputs low voltage and low impedance pulses which are used to measure capacitor ESR. I built the stepdown transformer from an inductor with a short secondary wrapped around it, and I used a 555 chip to supply low duty cycle pulses at high frequency. The 555 can supply enough current that it's possible to directly drive the transformer with a resistor in series with the primary.
My first attempt with a secondary of just a few turns worked pretty well when capacitors were plugged into the breadboard. However, test leads had enough impedance to make the circuit useless. Reducing the oscillation frequency to around 100 kHz and adding more turns to the secondary improved performance, making the bad capacitors very obvious. Test leads were still a problem however. Adding a 1Ω resistor in series with the secondary improved the situation significantly, so I proceeded to test the small capacitors on the motherboard via test leads.
It seems the small capacitors are all ok. However, among the large capacitors, even most that weren't bulging are bad. Only two of the ten 1000µF capacitors have a low ESR. Of course, considering the other failures, these shouldn't be used for anything either.
Now I would like to repair the motherboard, mainly because the combination of a Pentium 3, 640MB of RAM and an ISA slot could provide a nice way to use old hardware. By now, even more capacitors are obviously bad. However, only the GSC 1000µF and 1500µF 6.3V capacitors with gold/brown lettering have obvious problems and more numerous smaller GSC capacitors with silver/white lettering seem fine.
I didn't feel like unnecessarily replacing the smaller capacitors, so I quickly built a very simple capacitor ESR tester. The basic idea is the same as various other ESR measuring devices documented online: a stepdown transformer outputs low voltage and low impedance pulses which are used to measure capacitor ESR. I built the stepdown transformer from an inductor with a short secondary wrapped around it, and I used a 555 chip to supply low duty cycle pulses at high frequency. The 555 can supply enough current that it's possible to directly drive the transformer with a resistor in series with the primary.
My first attempt with a secondary of just a few turns worked pretty well when capacitors were plugged into the breadboard. However, test leads had enough impedance to make the circuit useless. Reducing the oscillation frequency to around 100 kHz and adding more turns to the secondary improved performance, making the bad capacitors very obvious. Test leads were still a problem however. Adding a 1Ω resistor in series with the secondary improved the situation significantly, so I proceeded to test the small capacitors on the motherboard via test leads.
It seems the small capacitors are all ok. However, among the large capacitors, even most that weren't bulging are bad. Only two of the ten 1000µF capacitors have a low ESR. Of course, considering the other failures, these shouldn't be used for anything either.
Subscribe to:
Posts (Atom)