Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only ~52% of CPU available - background processes #314

Open
alexblack opened this issue May 31, 2016 · 5 comments
Open

Only ~52% of CPU available - background processes #314

alexblack opened this issue May 31, 2016 · 5 comments

Comments

@alexblack
Copy link

alexblack commented May 31, 2016

I'm processing images on the Solo, and realizing that performance is slower than it might be due to background processes using some of the CPU. For example, after killing some processes time to run cv2.Canny on an image dropped from 250ms to 150ms.

I wrote a python program cpu.py to do an infinite loop, and top reports it uses ~52% cpu:

Mem: 142636K used, 369248K free, 0K shrd, 16168K buff, 58708K cached
CPU:  73% usr  22% sys   0% nic   0% idle   0% io   0% irq   3% sirq
Load average: 2.45 1.06 0.40 2/80 949
  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
  933   894 root     R     5924   1%  54% python cpu.py

Can I kill some of these processes without much impact? I'm flying the drone using dronekit, but also using the remote occasionally to abort a flight, or move the drone around manually. Not using the gimbal, or smart shot, or much else.

  • /usr/bin/main.py - Looks like used for smart shot?
  • /usr/bin/telem_forwarder - Looks like used for smart shot?
  • /usr/bin/pixrc - when I killed this the drone made a noise and lights flashed... d'oh

Sample CPU logging:

2016-05-31 06:03:12,468
   pid name                  utime  stime  pct
   895 (python)                 78     31  11%
   881 (telem_down)             19     87  11%
    71 (mmcqd/0)                 0     61   6%
   899 (python)                 37     17   5%
    64 (kworker/0:2)             0     53   5%
   896 (python)                 34      4   4%
   883 (pixrc_udp)               4     21   3%
   880 (python)                 12      3   2%
   872 (dataflash_logge)         5      7   1%
   898 (python)                  5      0   1%
@peterbarker
Copy link
Contributor

On Mon, 30 May 2016, Alex Black wrote:

Can I kill these processes without any impact?

No. They're there for a reason :-) OTOH, you can probably do without
some of the functionality.

  • /usr/bin/main.py - Looks like used for smart shot?

Not sure what this does. I do believe it is smart shots, 'though.

  • /usr/bin/telem_forwarder - Looks like used for smart shot?

telem_forwarder takes telemetry data from the PixHawk and gives it out to
clients - most notably Artoo.

Kill this one if you don't care about being able to fly your Copter....

  • /usr/bin/pixrc - when I killed this the drone made a noise and lights flashed... d'oh

Likewise :-)

Peter Barker | Programmer,Sysadmin,Geek.
[email protected] | You need a bigger hammer.
:: It's a hack! Expect underscores! - Nigel Williams

@alexblack
Copy link
Author

@peterbarker ok, so sounds like I can kill /usr/bin/.main.py then?

What is Artoo?

@alexblack
Copy link
Author

alexblack commented May 31, 2016

Say my goal here is to fly the drone as bare bones as possible, is there anything else I might be able to do without?

telem_forwarder appears to take 10-12% cpu

  PID  PPID USER     STAT   VSZ %VSZ %CPU COMMAND
 8213  8199 root     S    29900   6%  13% /usr/bin/telem_forwarder
 8150     2 root     SW       0   0%   7% [kworker/0:2]
 7488     1 root     S    29968   6%   2% /usr/bin/pixrc
  880     1 root     S    12624   2%   2% dataflash_logger

@alexblack alexblack changed the title Removing background processes - CPU is being used Only ~52% of CPU available - background processes May 31, 2016
@hamishwillee
Copy link
Contributor

Artoo is the internal name for the Solo Controller. The forwarder sends telemetry to the controller.

@alexblack
Copy link
Author

alexblack commented Jun 5, 2016

I've freed up a lot of the CPU from background processes by commenting out these lines in /etc/inittab and then restarting the solo:

#TOP:345:respawn:proc_top /log/3dr-top.log
#TEMP:345:respawn:log_temp
#DSYN:4:respawn:dataFlashMAVLink-to-artoo.py
#DFL:4:respawn:dataflash_logger
#API:4:respawn:run_shotmanager.sh

Then, before calling dronekit.connect you need to fire up Mav (which used to be done, along with shot manager, in /usr/bin/run_shotmanager.sh):

def startMav():
  """Requried if you're not running `/usr/bin/run_shotmanager.sh` on the Solo"""
  print "Starting up MAV..."
  from dronekit_solo import SoloVehicle
  from dronekit.mavlink import MAVConnection
  mav_vehicle = dronekit.connect("udpout:127.0.0.1:14560", wait_ready=False, vehicle_class=SoloVehicle, source_system=255, use_native=True, heartbeat_timeout=-1)
  out = MAVConnection("udpout:127.0.0.1:14550", source_system=254)
  mav_vehicle._handler.pipe(out)
  out.start()    
  print "Sleeping 5s to let MAV start..."
  # Not sure if this sleep is needed or not...
  time.sleep(5)
  print "Started MAV."

This combined with setting my process priority higher:

def setProcessPriority():
  """Set our process priority high so we get more CPU time hopefully"""
  import os, psutil
  p = psutil.Process(os.getpid())
  old = p.nice()
  p.nice(-20)
  print "Process {} priority set from {} to {}".format(p, old, p.nice())

Has got my process's CPU usage up from ~52% to ~92%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants