Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #26428

Re: Delayed "printf"

From Hans-Bernhard Bröker <HBBroeker@t-online.de>
Newsgroups comp.arch.embedded
Subject Re: Delayed "printf"
Date 2017-04-25 21:03 +0200
Message-ID <em9kstFcktjU1@mid.dfncis.de> (permalink)
References <R6WdnUr9KJ3rBmPFnZ2dnUU7-K2dnZ2d@giganews.com>

Show all headers | View raw


Am 25.04.2017 um 02:42 schrieb Tim Wescott:

> Just how dumb is it to have "printf" queue up the format string AND the
> parameters into a buffer, to be printed out in some low-priority task?

Exactly as dumb as using printf() at all while being concerned about CPU 
cycles at all.  I.e. the first rule of adding actual printf()s in the 
hot path is:

	DON'T.

Using the real printf for this effectively impossible, if only because 
there's essentially no way to know, in the general case, what needs to 
be stored in that printf job queue to be able to execute it later, 
without parsing the entire format string first.  That parse alone will 
likely already take longer than you can afford.

You need to use something else; if it's to resemble printf(), it'll have 
to be _considerably_ pared down to forbid all the 
impossible-to-implement features: no * widths, no * precisions, no %s 
format, no %n format, best no int128_t, long doubles, etc.

A much saner function whose calls can be queued up for later playback 
would look like this:

	void deb_out(t_typeToPrint type, /* enum of allowed types */
	             size_t size,  /* refuse if size > some limit */
	             void *data           /* copied at call time! */
	            );

Based on that one might wish to make convenience (inline?) wrappers like:

	void deb_out_u8(uint8_t value)
	{
		deb_out(E_TYPE_TO_PRINT_U8, 1, &value);
	}
	void deb_out_u16(uint16_t vlaue)
	...

and maybe, if you have near-perfect control over who gets to use this, 
even some rather risky ones:

	void deb_out_f_float(const char *fmt, float value)
	{
	   deb_out(E_TYPE_TO_PRINT_FORMATSTRING, strlen(fmt), fmt);
	   deb_out(E_TYPE_TO_PRINT_FLOAT, sizeof(float), &value);
	}

The worker thread would synthesize a call of snprintf() or similar from 
those two entries.  Entries without a preceding 
E_TYPE_TO_PRINT_FORMATSTRING one are printed with a default format.

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Delayed "printf" Tim Wescott <seemywebsite@myfooter.really> - 2017-04-24 19:42 -0500
  Re: Delayed "printf" Don Y <blockedofcourse@foo.invalid> - 2017-04-24 18:51 -0700
    Re: Delayed "printf" Tim Wescott <tim@seemywebsite.com> - 2017-04-24 21:54 -0500
      Re: Delayed "printf" Don Y <blockedofcourse@foo.invalid> - 2017-04-24 21:27 -0700
  Re: Delayed "printf" Paul Rubin <no.email@nospam.invalid> - 2017-04-24 19:53 -0700
  Re: Delayed "printf" Clifford Heath <no.spam@please.net> - 2017-04-25 13:01 +1000
    Re: Delayed "printf" Theo Markettos <theom+news@chiark.greenend.org.uk> - 2017-04-25 18:51 +0100
      Re: Delayed "printf" Clifford Heath <no.spam@please.net> - 2017-04-26 12:59 +1000
        Re: Delayed "printf" Theo Markettos <theom+news@chiark.greenend.org.uk> - 2017-04-26 13:24 +0100
  Re: Delayed "printf" Robert Wessel <robertwessel2@yahoo.com> - 2017-04-25 00:19 -0500
    Re: Delayed "printf" David Brown <david.brown@hesbynett.no> - 2017-04-25 10:44 +0200
      Re: Delayed "printf" Robert Wessel <robertwessel2@yahoo.com> - 2017-04-25 09:22 -0500
        Re: Delayed "printf" David Brown <david.brown@hesbynett.no> - 2017-04-25 16:37 +0200
    Re: Delayed "printf" Tim Wescott <tim@seemywebsite.com> - 2017-04-25 10:49 -0500
  Re: Delayed "printf" Jack <jack4747@gmail.com> - 2017-04-24 23:33 -0700
  Re: Delayed "printf" Tom Gardner <spamjunk@blueyonder.co.uk> - 2017-04-25 08:09 +0100
  Re: Delayed "printf" John Devereux <john@devereux.me.uk> - 2017-04-25 08:14 +0100
  Re: Delayed "printf" David Brown <david.brown@hesbynett.no> - 2017-04-25 10:58 +0200
  Re: Delayed "printf" Stefan Reuther <stefan.news@arcor.de> - 2017-04-25 18:46 +0200
  Re: Delayed "printf" Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2017-04-25 21:03 +0200
  Re: Delayed "printf" Tim Wescott <seemywebsite@myfooter.really> - 2017-04-25 16:11 -0500
    Re: Delayed "printf" Les Cargill <lcargill99@comcast.com> - 2017-04-25 17:28 -0500
    Re: Delayed "printf" Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2017-04-26 10:03 +0300
  Re: Delayed "printf" Dave Nadler <drn@nadler.com> - 2017-04-25 14:31 -0700
  Re: Delayed "printf" Les Cargill <lcargill99@comcast.com> - 2017-04-25 17:25 -0500
  Re: Delayed "printf" mac <acolvin@efunct.com> - 2017-04-26 17:22 +0000
    Re: Delayed "printf" Grant Edwards <invalid@invalid.invalid> - 2017-04-26 17:37 +0000
      Re: Delayed "printf" Grant Edwards <invalid@invalid.invalid> - 2017-04-26 17:38 +0000

csiph-web