# A Few General Questions About FreeBSD 8.1



## Ruler2112 (Jan 14, 2011)

How does one get the power to go off on the machine when executing the halt command?  Currently I get a message saying press any key to reboot.  The only way to power down at this point is to hold the power button down for 4 seconds; simply pressing it once doesn't do anything.



Delete works like backspace and deletes the character before the one that the cursor is on.  I've used FreeBSD on several servers before and have just ignored this quirk - relatively easy to do since I don't have to operate on the console much.  With this new machine being my primary system, I want to fix it because I can see it'll be a continual annoyance.  I have an old standard 101-key IBM clicky-style keyboard that works 100% otherwise.  How would one go about making the delete key behave like it does in every other OS and delete the character the cursor is on?



When I boot, I have the following lines:


```
usbus0: 12Mbps Full Speed USB v1.0
usbus1: 12Mbps Full Speed USB v1.0
usbus2: 12Mbps Full Speed USB v1.0
usbus3: 12Mbps Full Speed USB v1.0
usbus4: 480Mbps Full Speed USB v2.0
```

How do I identify which bus is which physical port of the box?  I obviously want to use the 480 megabit port, but have no idea how to tell which is which.  (I have an active USB extension cable to extend one port from the computer to my desk, so only need to plug it in once and should be good.)  I'd thought of plugging in a flash drive into each port and run a benchmark copying a big file over each, but figure there's a simpler way that I just don't know about.



Some other boot messages:


```
real memory: 4294967296 (4096 MB)
avail memory: 4113428480 (3922 MB)
...
ZFS NOTICE: Prefetch is diabled by default if less than 4GB of RAM is present.
            to enable, add "vfs.zfs.prefetch_disable=0" to /boot/loader.conf
ZFS filesystem version 3
ZFS storage pool version 14
...
```

After the system is done booting, vfs.zfs.prefetch_disable is set to 1.  Am I correct in thinking that this means prefetching is disabled?  If so, is it due to the small amount of RAM reserved for the onboard video?  Is it something that I should be concerned about or address to obtain better performance/more stable operation?  Should I override it in /boot/loader.conf and force prefetching?  Would getting a standalone video card or bumping the RAM to 6 or 8 gig be a better option?  The system has regular PCI slots, one PCI-X slot, and a PCI-e x4 port.  I can find PCI video cards for sale, but no PCI-X or PCIe x4 video cards.



I believe I'm ready to start building the software I need to use this system as my desktop - X, KDE, etc.  I remember reading many years ago when I initially built our mail server that there are config files you can put flags into that will automatically tell the compiler to optimize the binaries produced for your specific system.  However, I did not bookmark the pages and don't remember specifics.  Does anybody know what I'm talking about?  If so, could you recommend any sites with more information on the subject?  It's not critical, but if there's something simple on a software-level that I can do to squeeze more performance out of the system, I'm more than happy to do it.


----------



## wblock@ (Jan 14, 2011)

Ruler2112 said:
			
		

> How does one get the power to go off on the machine when executing the halt command?  Currently I get a message saying press any key to reboot.  The only way to power down at this point is to hold the power button down for 4 seconds; simply pressing it once doesn't do anything.



shutdown(8) is used for that on FreeBSD:
`# shutdown -p now`



> Delete works like backspace and deletes the character before the one that the cursor is on.  I've used FreeBSD on several servers before and have just ignored this quirk - relatively easy to do since I don't have to operate on the console much.  With this new machine being my primary system, I want to fix it because I can see it'll be a continual annoyance.  I have an old standard 101-key IBM clicky-style keyboard that works 100% otherwise.  How would one go about making the delete key behave like it does in every other OS and delete the character the cursor is on?



For csh, add this line to .cshrc:

```
bindkey "\e[3~" delete-char
```



> I believe I'm ready to start building the software I need to use this system as my desktop - X, KDE, etc.  I remember reading many years ago when I initially built our mail server that there are config files you can put flags into that will automatically tell the compiler to optimize the binaries produced for your specific system.



That would be /etc/make.conf.  Setting CPUTYPE in that file may make an improvement.  Do not set CFLAGS, it's a trap for the unwary.


----------



## UNIXgod (Jan 14, 2011)

does shutdown -p work for you?


----------



## phoenix (Jan 15, 2011)

USB 2.0 ports are backward compatible with USB 1.1, meaning that unless you have a motherboard that only supports USB 1.1, and you added a separate USB 2.0 card, *all* your USB ports support 480 Mbps.

The way USB controllers work is something like the USB 1.1 driver (ohci(4), uhci(4)) control the ports; then the USB 2.0 driver (ehci(4)) piggy-backs ontop, and manages the high speed transfer.

There's a new driver (xhci(4)) coming that will support USB 3.0, and replace the ehci, ohci, and uhci drivers.


----------



## Galactic_Dominator (Jan 15, 2011)

Ruler2112 said:
			
		

> How do I identify which bus is which physical port of the box?  I obviously want to use the 480 megabit port, but have no idea how to tell which is which.  (I have an active USB extension cable to extend one port from the computer to my desk, so only need to plug it in once and should be good.)  I'd thought of plugging in a flash drive into each port and run a benchmark copying a big file over each, but figure there's a simpler way that I just don't know about.



Connect your USB device and run usbconfig() to verify it's enumerated on the correct bus.


----------



## Ruler2112 (Jan 17, 2011)

Thanks for the info guys.


shutdown -p works great - thanks for the tip.  Was not aware of the -p switch and feel kinda stupid for not looking in the man page for it... usually it's the first place I look.


I've tried the bindkey option in both root and a user account, but there seems to be no difference in behavior with or without it.  I've logged out and back in again after making the change and even tried a full reboot - delete is still being taken as backspace.  env shows that SHELL is set to /bin/csh and I've tried putting the bindkey line at the beginning on the .cshrc file and at the end of it - neither seemed to have any effect.


Sorry - I don't think I was entirely clear on the USB question.  All of the USB ports in this box are built-in to the motherboard.  I was just looking to ascertain which was which so that I could use the fastest one available.  The usbconfig command showed exactly what I needed and I was able to tell that the front USB ports are high speed while the ones soldered onto the board are all slow.  (I'd think it'd be the opposite, but it's no big deal either way.  I'm using an active USB extension cable to extend the USB port on this machine from the box across the office over to my desk.)


Anybody have input on the ZFS/RAM condition?


LOL - I love your comment about using CFLAGS in /etc/make.conf being 'a trap for the unwary'...    I read the man page on how to set the CPUTYPE parameter, but have another question related to this.

In startup:

```
CPU: Intel(R) Pentium(R) D CPU 2.80 GHz (2798.61-MHz K8-class CPU)
  Origin = "GenuineIntel" Id=0xf44 Family=f Model=4 Stepping=4
  Features=0xbfebfbff<FPU,VME,DE,PSE,RSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,
    MOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
  Features2=0x641d<SSE3,DTES64,MON,DS_CPL,CNXT-ID,CX16,xTPR>
  AMD Features=0X20100800<SYSCALL,NX,LM>
  TSC: P-state invariant
..
ACPI APIC Table: <INTEL 04DT044>
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
FreeBSD/SMP: 1 package(s) x 2 core(s)
  cpu0 (BSP): APIC ID: 0
  cpu1 (AP): APIC ID: 1
ioapic0: Changing APICID to 5
ioapic0 <Version 2.0> irqs 0-23 on motherboard
```

Looking in /usr/share/examples/etc/make.conf as directed by the man page for make.conf for a list of CPUTYPEs available, I found:

```
Currently the following CPU types are recognized:
  Intel x86 architecture:
    (AMD CPUs)    opteron athlon64 athlon-mp athlon-xp athlon-4
                  athlon-tbird athlon k8 k6-3 k6-2 k6 k5
    (Intel CPUs)  core2 core nocona pentium4m pentium4 prescott
                  pentium3m pentium3 pentium-m pentium2
                  pentiumpro pentium-mmx pentium i486 i386
    (Via CPUs)    c3 c3-2
  Alpha/AXP architecture: ev67 ev6 pca56 ev56 ev5 ev45 ev4
  AMD64 architecture: opteron, athlon64, nocona, prescott, core2
  Intel ia64 architecture: itanium2, itanium
```

I'm using the amd64 distro as recommended to use ZFS.  However, none of them seem close to the CPU I actually have from what I can see.  pentium4 looks to be most appropriate, though it appears that it'd build a 32-bit OS if I were to use that.  Am I missing something or should I just forget about setting the CPUTYPE to optimize the compiler?  (I was thinking compiling for a dual-core system would help; I've done this with ffmpeg in the past and saw a big performance boost due to it utilizing both CPUs when transcoding video, but that was using a simple command-line flag to tell it to use multiple cores.)

When trying to find the answer to this myself, I discovered a few other flags mentioned for this file - does anybody have input on their use?  I've included the description for them as well.

BUILD_OPTIMIZED - use when you need speed
BUILD_STATIC - use when you need more speed
NO_INET6 - disable IPv6  (I'm on a LAN and we're not going to IPv6 anytime soon, so this would likely be useful to me.)



Sorry for the simplistic questions everybody - I appreciate your patience and help.


----------



## wblock@ (Jan 18, 2011)

Yes, delete works differently depending on whether it's a real console or an xterm (or xfce Terminal).  I just switched to mostly using Terminal and just cussing when the console delete did a backspace.

But now you've motivated me to go back and fix it.  So here's what to do in .cshrc:

```
...

bindkey "\e[3~" delete-char
bindkey "\e[1~" beginning-of-line

# do things differently for a real console
switch ($tty)
  case "ttyv*":
    alias precmd /usr/sbin/kbdcontrol -r fast
    bindkey "^?" delete-char
endsw

...
```

Use the ANSI escape sequence as a default, but when it's a real console, interpret "^?" as delete instead.  (Also crank the repeat rate up.  You could comment that, but it makes a machine so much faster to use.)

Thanks for bringing that up, it's nice to have it fixed.  Don't know why I didn't do that before.


----------



## Ruler2112 (Jan 19, 2011)

That code in the .cshrc file works perfectly - delete is now delete instead of backspace!     Thank you so much for the info.


I've been doing research the CPUTYPE parameter and have found everything from people saying to never set it because it'll cause problems to people saying to always set it because it substantially increases speed.  I found a discussion on the mailing list with code that is supposed to tell you what to set it to, but it doesn't work on 8.1 and I'm nowhere near good enough to figure out why not or fix it.   I've found information on various CPUs, but not my specific one, so I'll probably just leave it unset.  I can't believe that there's not an easy-to-find database of CPUs and what CPUTYPE to reference in order to optimize performance...


Should I be concerned about ZFS and the above message about prefetching?


----------



## wblock@ (Jan 19, 2011)

Ruler2112 said:
			
		

> That code in the .cshrc file works perfectly - delete is now delete instead of backspace!     Thank you so much for the info.



You're welcome.  If you use editors/nano, edit .nanorc to add

```
set rebinddelete
```



> I've been doing research the CPUTYPE parameter and have found everything from people saying to never set it because it'll cause problems to people saying to always set it because it substantially increases speed.



My experience is that setting CPUTYPE makes for a perceived slight improvement on netbooks with Atom processors.  This could be Hawthorne effect.  I've never encountered a problem due to CPUTYPE, at least AFAIK.

This would be a good case for a benchmark, if you're so inclined.


----------



## Galactic_Dominator (Jan 20, 2011)

wblock said:
			
		

> My experience is that setting CPUTYPE makes for a perceived slight improvement on netbooks with Atom processors.  This could be Hawthorne effect.  I've never encountered a problem due to CPUTYPE, at least AFAIK.



My guess about the problems with CPUTYPE is the occasional attempt by someone to hack the kernel makefiles to insert CPUTYPE optimizations.  That pretty much always ends in pain.

The base gcc is old enough that it doesn't support at lot of newer cpu features like sse4.  If you install something like gcc44 and compile with that, certain application could receive around a 10% boost in speed.  There is a short limit on what ports can easily be compiled with alternative compilers though.

Also the cputypes listed in the make.conf example are not all unique, many are just aliases to each.  For example, setting core2 or core is the same as nocona.  Easiest thing to do is leave it blank and gcc will autodetect and create the same binaries it would if you set your CPUTYPE correctly.


----------



## jem (Jan 21, 2011)

Ruler2112 said:
			
		

> Sorry - I don't think I was entirely clear on the USB question.  All of the USB ports in this box are built-in to the motherboard.  I was just looking to ascertain which was which so that I could use the fastest one available.  The usbconfig command showed exactly what I needed and I was able to tell that the front USB ports are high speed while the ones soldered onto the board are all slow.  (I'd think it'd be the opposite, but it's no big deal either way.  I'm using an active USB extension cable to extend the USB port on this machine from the box across the office over to my desk.)



You'll probably find that all of your USB ports are high speed.

The listing of several USB 1.1 busses and one USB 2.0 bus is standard.  As a previous poster pointed out, that single instance of a fast bus actually relates to all the ports on your motherboard (unless your motherboard is highly unusual).


----------



## phoenix (Jan 21, 2011)

Ruler:  read what I wrote.  *ALL* of your USB ports are USB 2.0, meaning they can operate at 480 Mbps.  And they can also fall-back to USB 1.1 at 12 Mbps or 1 Mbps.


----------



## Ruler2112 (Jan 21, 2011)

phoenix said:
			
		

> Ruler:  read what I wrote.  *ALL* of your USB ports are USB 2.0, meaning they can operate at 480 Mbps.  And they can also fall-back to USB 1.1 at 12 Mbps or 1 Mbps.



Sorry - I mis-understood your previous post, but reading it again now believe I understand.  (Hence, the light bulb on this post - it's what went on after re-reading a few times.   )  Please correct me if I'm wrong on this:

There's a driver that interfaces with the physical port at USB1 speeds, but for high speed ports, another driver sits on top and overrides the speed settings in the driver underneath.  Even though it shows as having USB2.0 on a different bus number, that's a 'virtual bus' created by the top-level driver.  This explains why there are there are 4 buses with 2 ports each at USB1 speeds, but the USB2 bus shows as having 8 ports - the USB2 driver loaded a single instance of itself to handle high speed transfers over all the individual USB1 ports, but a separate instance of the USB1 driver loaded for each of the 4 physical hubs.  Am this close?  (I'm quite honestly surprised that it was designed like this... I assumed that the USB2 driver would load for USB2 ports and simply throttle the transfer rate way down if the port couldn't support it.)

I did test and both the front and back ports are indeed USB2.  I was afraid that the machine was going to be something what jem intimated, wacky hardware that I always seem to find.  

Sorry for the confusion caused by my lack of understanding.



I would be up for testing the effect of the CPUTYPE parameter on this system - what benchmark would be the best/most effective to use?  I'm thinking something that does lots of complex math and has a high precision timer built in to isolate the CPU as much as possible, but have never benchmarked anything but drive transfer rates in unix before and don't know where to begin.

I will build something, rename the output, set the CPUTYPE, build it again, and do a binary comparison between the two output files.  This should confirm whether the compiler is smart enough to set it on it's own or not.

Does anybody have any experience with or comments on using the BUILD_OPTIMIZED, BUILD_STATIC, or NO_INET6 flags in make.conf?


----------



## phoenix (Jan 22, 2011)

Ruler2112 said:
			
		

> Please correct me if I'm wrong on this:
> 
> There's a driver that interfaces with the physical port at USB1 speeds, but for high speed ports, another driver sits on top and overrides the speed settings in the driver underneath.  Even though it shows as having USB2.0 on a different bus number, that's a 'virtual bus' created by the top-level driver.  This explains why there are there are 4 buses with 2 ports each at USB1 speeds, but the USB2 bus shows as having 8 ports - the USB2 driver loaded a single instance of itself to handle high speed transfers over all the individual USB1 ports, but a separate instance of the USB1 driver loaded for each of the 4 physical hubs.  Am this close?  (I'm quite honestly surprised that it was designed like this... I assumed that the USB2 driver would load for USB2 ports and simply throttle the transfer rate way down if the port couldn't support it.)



I can't tell you the specifics of how the driver works (C code looks like Egyptian hieroglyphs to me), but that's the gist of it, yes.


----------

